This should be easy for one of you pros out there...
I take a single string(one letter) from a textbox and want to query my
database for a name that starts with that letter.
I know that the correct synthax when you know the letter is:
WHERE FirstName LIKE 'O%'
but when I have this:
*****************
Dim lastname As String
lastname = txtlastname.Text
Dim strSQL As String = "SELECT * FROM [" & PubName & "] WHERE Last_Name
like ' txtlastname % ' "
**********************************************
It doesn't seem to work since my datagrid is empty afterwards. I also
tried:
***************
Dim strSQL As String = "SELECT * FROM [" & PubName & "] WHERE Last_Name
like '" & txtlastname & " % ' "
****************
without succes...
It's probably just a synthax error on my part but I don'T know were..
THanks guys!!
JMTIt may just be a posting error, but it looks as if you have a couple of
spaces in your string construction; the second looks closer to correct:
Dim strSQL As String = "SELECT * FROM [" & PubName & "] WHERE
Last_Name
like '" & txtlastname & "%'
Assuming that PUBNAME is a table named TABLE, and txtLastName = A, then
the final SQL String should look like:
SELECT * FROM [TABLE] WHERE Last_Name LIKE 'A%',
Stu
No comments:
Post a Comment