• Once the ADO data control is connected to a
database,
we need to assign a table to that control. Recall each data control is attached
to a single table, whether it is a table inherent to the
database or the virtual
table we discussed. Assigning a table is done via the
RecordSource
property.
• Tables are assigned by making queries of the database.
The language used to make a query is SQL (pronounced ‘sequel,’
meaning structured query language). SQL is an English-like language that has evolved
into the most widely used database query language. You use SQL to formulate a
question to ask of the database. The data base ‘answers’ that question
with a new table of records and fields that match your criteria.
• A table is assigned by placing a valid SQL statement
in the RecordSource property of a data control. We won’t
be learning any SQL here. There are many texts on the subject - in fact, many
of them are in the BIBLIO.MDB database we’ve been using. Here we simply
show you how to use SQL to have the data control ‘point’ to an inherent
database table.
• Click on the ellipsis next to RecordSource
in the property box. A Property Pages dialog box will
appear. In the box marked Command Text (SQL), type this line:
SELECT * FROM TableName
This will select all fields (the * is a wildcard)
from a table named TableName in the database. Click OK.
• Setting the RecordSource property
also establishes the Recordset property, which we will see later
is a very important property.
• In summary, the relationship between the data
control and its two primary properties (ConnectionString
and RecordSource) is:
