Visual Basic Database Tutorial - Part 3, Page 6
Hmm, queries, queries, queries. Remember that SQL program we created just last week? The one into which we type a few "select * from customers" statements and clicked a button to view the results?
Well, a query is basically one of those SQL questions... stored inside a database, under a particular name.
If you've still got the last Access query open, hit File and Save. Tap in the name "qryContacts" and click OK.
Erm, there we have it. You've just created your first query.
Close the current window and returned to the "Nwind: Database" screen. Take a peek under the 'Queries' tab and double-click on your query. Wallah!
A query is just like a table - although in realistic terms, it probably only grabs a few elite records matching your criteria. But it can be treated just like a table.
For example, if you pop back into that SQL program we created and type in "select * from qryContacts" - you'll find it will display everything returned by the qryContacts query.
Or you could try simply stating, "select ContactName from qryContacts" - which would only return the ContactName fields from the query. Go on, try it!
Top Tip: Some database whizz-kids also call queries, 'views'. Just nod and ignore them... after all, we know who's right, don't we?
The advantage of queries is they allow you to store SQL statements outside of Visual Basic. Let's say you had a customer order table with a True/False value depending on whether payment had been received. You could create a query that shows you all the customers that haven't paid - and display that in your program - without having to store all the SQL in Visual Basic.
And if you ever need to make changes to the query - you can simply edit it. No recompiling required!
Well that's enough of that. Next, let's dive into Visual Basic and create our first real database-integrated application!
Page 6 of 10