sql query not meeting conditions
The following code is looking for the phone number of contacts in a database when the column "hoohoo" = 15. However it doesnt keep to this condition, but displays all of the numbers. Am i missing a line that tells it to keep to the condition???
Code:
Dim SQL As String = "SELECT *, Phone FROM TblContacts WHERE Hoodoo=15"
Dim myOleDbCommand As New OleDb.OleDbCommand(SQL, con)
con.Open()
Dim count As Int32 = Convert.ToInt32(myOleDbCommand.ExecuteScalar())
Using myDataReader As OleDb.OleDbDataReader = myOleDbCommand.ExecuteReader()
If myDataReader.Read() Then
While myDataReader.Read()
' txtPhone.Text =
numbers.Text += myDataReader.Item("Phone").ToString + vbCrLf
notfound = 0
End While
Re: sql query not meeting conditions
Quote:
Originally Posted by
youngnoviceinneedofh
The following code is looking for the phone number of contacts in a database when the column "hoo
hoo" = 15. However it doesnt keep to this condition, but displays all of the numbers. Am i missing a line that tells it to keep to the condition???
Code:
Dim SQL As String = "SELECT *, Phone FROM TblContacts WHERE Hoodoo=15"
Dim myOleDbCommand As New OleDb.OleDbCommand(SQL, con)
con.Open()
Dim count As Int32 = Convert.ToInt32(myOleDbCommand.ExecuteScalar())
Using myDataReader As OleDb.OleDbDataReader = myOleDbCommand.ExecuteReader()
If myDataReader.Read() Then
While myDataReader.Read()
' txtPhone.Text =
numbers.Text += myDataReader.Item("Phone").ToString + vbCrLf
notfound = 0
End While
Perhaps that difference in the letters - hoohoo vs. Hodoo
And, why are you using asterisk (*) in your SQL query?
If you only need the phone number you just use:
Code:
SELECT Phone FROM TblContacts WHERE ...
Re: sql query not meeting conditions
My thread was incorret, the code was right. sorry. Yeah i'll try taking the * out, thanks.