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
Returning value from database
Page 1 of 11 Replies - 107 Views - Last Post: 01 October 2012 - 08:18 AM
#1
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
Replies To: Returning value from database
#2
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 = ?)
Example:
"SELECT Question, AnswerFROM [Tbl_Q&A]WHERE(Question = ?)
Should read:
"SELECT Question, Answer FROM [Tbl_Q&A] WHERE (Question = ?)
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|