problem with sql on dataset

ninjaimp

Well-known member
Joined
Jun 13, 2007
Messages
80
Programming Experience
1-3
hi



i am just starting with vb.net and have set a connection to an existing access db that i have and am able to get the data displayed on a form.



my problem lies where as i want to setup a basic search. i have added a query to a datagrid to dispaly data based on text in a text box.



now my sql query is this:



SELECT CustID, CustName, CustAddress, CustPostcode, CustTel, CustEmail, CustNotes, CustRoom, CustStayArrive, CustStayLeave
FROM tblCustData
WHERE CustName = '"& SearchBox.text &"'




now i get no errors but also no data gets returned. If i add the actual value of one of the records that one gets returned fine but doesnt really help with a search.



wondered if anyone had any ideas?



regards
 
Look into using parameterized queries.

Your line
VB.NET:
WHERE CustName = '" & SearchBox.text & "'
should have an additional double quote at the end
VB.NET:
... SearchBox.text & "'"
to enclose the single quote as a string.
 
if i add that then i get an error. Please note that im building this query in the query configuration wizard, if that makes a difference
 
If you're building it in the Query Builder then you should be able to put @CustName in the filter box which will change your query to:
VB.NET:
...WHERE CustName = @CustName
Clicking on the Execute Query button will test the query out and show you that it's waiting to have a value passed in.
 
now i have tried this based on the tutorials i have seen. When i put in @SearchBox it gives an error. What does the @ bit do?

thanks for your help
 
Back
Top