Link to home
Start Free TrialLog in
Avatar of salman_sulaiman_2008
salman_sulaiman_2008

asked on

How Can I Write An SQL "Select" Query To Select Based On The Text Entered By The User In The "Textbox" Control?

Greetings Everyone!
I am really stuck at the moment and can't figure out this. I hope someone could help. this is what I am trying to do:
I have a search "Form", it is a Windows Application Form, and what I want to do is to let the user enter in a "TextBox" control the first name of a customer, and then during runtime excute an sql query to, it is a "SQL SELECT Query", I need this query to return the all the customer records from the Microsoft Access Datasbe Table, those reocrds where the customers full names start with the name the user has entered in the "TextBox" control on the form.

here is the code I wrote, as for testing the query, but I don't get any results, when I check the "SqlDataReader" using the "HasRows" property, it returns "False".
I have attached it in the code snippet.
now the strange thing, I have used the keyword "LIKE" in my query, and if I specify the full name of the customer which happens to be "Mary S. Jones" then I get "True", which means the query has returned some rows, but when I use "Mary*"  then I get "False". the first part of the code in the Code Snippet returns "False" but the second version the one bellow it, returns "True".

I am totally stuck, and I tackle this problem.
and thanks in advance guys!

~Salman~



'This code Returns "False"
 
 Dim myconn As New OleDbConnection(My.Settings.MasterFileConnectionString2)
        Dim mycommand As New OleDbCommand("select * from customers where name LIKE 'Mary*'", myconn)
        myconn.Open()
        mycommand.CommandType = CommandType.Text
        Dim myreader As OleDbDataReader
        myreader = mycommand.ExecuteReader
        myreader.Read()
        MsgBox(myreader.HasRows)
 
 
 
'This code returns "True"
 Dim myconn As New OleDbConnection(My.Settings.MasterFileConnectionString2)
        Dim mycommand As New OleDbCommand("select * from customers where name LIKE 'Mary S. Jones'", myconn)
        myconn.Open()
        mycommand.CommandType = CommandType.Text
        Dim myreader As OleDbDataReader
        myreader = mycommand.ExecuteReader
        myreader.Read()
        MsgBox(myreader.HasRows)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of surajguptha
surajguptha
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of salman_sulaiman_2008
salman_sulaiman_2008

ASKER

ohh! Thanks Surajgupatha! I took your advise and it worked with the precentage sign, truely unbelieveable!
thanks again!

~Salman~
You are welcome :)