Using the ODBCDirect Object Model

Connecting to a Database

A CdbConnection object is similar to a CdbDatabase object. In fact, a CdbConnection object and a CdbDatabase object represent different references to the same object, and properties on each of these two object types allow you to obtain a reference to the other corresponding object, which simplifies the task of converting ODBC client applications that use Microsoft Jet to use ODBCDirect instead. Use the OpenConnection method to connect to an ODBC data source. The resulting CdbConnection object contains information about the connection, such as the server name, the data source name, and so on.

Queries

Although DAO does not support stored queries in an ODBCDirect workspace, a compiled query can be created as a CdbQueryDef object and used to execute action queries, and can also be used to execute stored procedures on the server. The Prepare property lets you decide whether to create a private, temporary stored procedure on the server from a CdbQueryDef before actually executing the query.

Parameter queries can also be passed to the server, using CdbParameter objects on the CdbQueryDef. The Direction property lets you specify a CdbParameter as input, output, or both, or to accept a return value from a stored procedure.

Data Manipulation

Creating a CdbRecordset object is a convenient way to query a database and manipulate the resulting set of records. The OpenRecordset method accepts an SQL string or a CdbQueryDef object (stored query) as a data source argument. The resulting CdbRecordset object features an extremely rich set of properties and methods with which to browse and modify data.

The CdbRecordset object is available in four different types  corresponding to ODBC cursor types as shown in the following table.

CdbRecordset Object Types ODBC Cursor Types
Dynamic Dynamic
Dynaset Keyset
Forward-only Forward-only
Snapshot Static

A batch update cursor library is available for client applications that need to work with a cursor without holding locks on the server or without issuing update requests one record at a time. Instead, the client stores update information on many records in a local buffer (or "batch"), and then issues a batch update.

Asynchronous Method Execution

The Execute, MoveLast, OpenConnection, and OpenRecordset methods feature the dbRunAsync option. This allows your client application to do other tasks (such as loading forms, for example) while the method is executing. You can check the StillExecuting property to see whether the task is complete and terminate an asynchronous task with the Cancel method.