Access, Database, Got it... Queries, not so much.

x2breakoffate

New member
Joined
Feb 28, 2008
Messages
1
Programming Experience
Beginner
So I understand this SELECT blahblah, blahbloo FROM Database WHERE (help)

This is where I get stuck because I wanna say something like

Select * (or Name, Address, Phone) FROM Addressbookdata WHERE Name = txtSearch.text

You see I have a search text box on my form and I'm trying to refer to it through here on the query builder. I understand that doing it the old way you'd just type out the select statement like "SELECT Name, Address, Phone FROM AddressData WHERE Name = " & txtSearch.text But how the heck do I do it in the builder. The builder clearly doesnt use quotes so there for concatinating will just bring the "&" symbol as an invalid, well, symbol.

Idk, someone please help.

Jack
 
Read the DW2 link in my sig, first "Creating a Simple Data App" then "Creating a Form to Search Data"
 
read the walkthrough that Cjard has linked.

Basically on your table adapter you create the parameterised query, i.e.
SELECT * FROM Orders WHERE CustomerID = @CustomerID

^^ @CustomerID is the parameter (for MS SQL it is anyway...).

When you save this query, give it a MEANINGFUL name such as FillByCustomerID


On your form, when you fill the dataTable, you would do something like:
me.OrderTableAdapter.FillByCustomerID(me.dsMyDataSet.Orders, me.txtSearch.text)

the value in txtSearch is what is used to fill the dataTable with that query. So if the textbox has 1 in it, the query is run with 1 representing @CustomerID.

It's better to put some validation in place, which the walkthroughs cover, as you can use any kind of control to provide the parameter to the query....
 
Back
Top