Querying a table requires ODBCConnection, ODBCQuery, and ODBCResultSet objects. You must explicitly associate the objects by setting the Connection property of ODBCQuery and the Query property of ODBCResultSet as follows:
The SQL property of ODBCQuery specifies the SQL statement that your query executes. The SQL property can be any valid SQL syntax, including SELECT, CREATE TABLE, DROP TABLE, INSERT, UPDATE, and DELETE statements. For example, the following SQL statement selects all data in the STUDENTS table:
An SQL query can include parameters. The following query contains one parameter named studentNo:
The Execute and ExecProcedure methods of the ODBCResultSet object perform your query and retrieve the selected data. You can limit the attempt time for the query by setting the QueryExecuteTimeOut property of ODBCQuery.
The selected data becomes available as a result set that contains one row for every row selected from the table, and one column for every field selected from the table. To access the data, use the ODBCResultSet object.
Use the IsResultSetAvailable method of the ODBCResultSet objec to determine whether a query returned any data.
When you no longer need a result set, close it with the Close method of ODBCResultSet.
Example