1 Replies - 252 Views - Last Post: 01 October 2012 - 08:18 AM Rate Topic: -----

#1 Pricey40  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 27-September 12

Returning value from database

Posted 01 October 2012 - 07:36 AM

Hi, I'm having a problem searching a database, I have used this method before validating passwords but it doesn't seem to work now. Also I do not know how to turn the result into text to output into the console window, thanks in advance

Sub Main()

        Dim UserQuestion As String = "How do I change my password?"
        Dim answer As String = "Send an email to the help desk"
        Dim conn As New System.Data.OleDb.OleDbConnection()
        conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Price\Documents\coursework\RNLI HelpCentre\Q&A database.accdb"
        Try
            conn.Open()
            Dim cmd As New OleDb.OleDbCommand("SELECT Question, AnswerFROM [Tbl_Q&A]WHERE(Question = ?)", conn)




            cmd.Parameters.Add(New OleDb.OleDbParameter("Question", UserQuestion))


            'THIS IS WHERE THE CODE STOPS WORKING
            Dim db_reader As OleDbDataReader = cmd.ExecuteReader(Commandbehavior.SingleRow)


            If db_reader.HasRows Then
                Console.WriteLine("Found")
            Else

            End If

        Catch ex As Exception
            Console.WriteLine("Failed to connect to data source")
        Finally
            conn.Close()
        End Try
        Console.ReadLine()



    End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: Returning value from database

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1623
  • View blog
  • Posts: 5,200
  • Joined: 25-September 09

Re: Returning value from database

Posted 01 October 2012 - 08:18 AM

Your select statement needs some spaces between your fields and keywords.

Example:
"SELECT Question, AnswerFROM [Tbl_Q&A]WHERE(Question = ?)
Should read:
"SELECT Question, Answer FROM [Tbl_Q&A] WHERE (Question = ?)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1