ActiveX Data Objects
ActiveX Data Objects (ADO) represents the future of data access methods and is a fundamental component of Universal Data Access.
ADO is the data interface to OLE DB. It is designed to access databases of various types. Unlike DAO and RDO, ADO is an extensible programming model. It uses independent data service providers to access specific databases.
ADO vs. RDO and DAO
Unlike RDO, ADO is an independent object model. This means that ADO is positioned to be the data access interface of choice over both DAO and RDO. ADO is not a specific "implementation" of a data access interface like RDO or DAO; it is a data programming model. Future extensions of ADO will allow you to take advantage of specific functionality provided by different data sources, such as the Jet database engine.
Future of ADO
ADO will eventually provide a superset of RDO 2.0 functionality, a far more sophisticated interface, and an updated programming model. Since ADO is a COM-based component, any application or language capable of working with COM objects can use it.
Connecting With ADO
Unlike with DAO or RDO, when using ADO your code does not have to work its way through the object hierarchy. Instead of creating
Workspace and
Database objects, ADO can make a direct reference to a
Recordset object. The syntax for connecting using ADO is similar to the syntax for RDO.
Setting the ADO Reference
As required when using DAO and RDO, your application must first have a reference to the ADO object library. At the time of writing, this library is the
Microsoft ActiveX Data Objects 1.5 Library .
Opening a Recordset
Using ADO, you can open a recordset using the
Open method. For a complete ADO syntax reference, use the object browser in Visual Basic.
Example
This example creates a simple connection to a SQL Server database using Visual Basic and ADO:
Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset rs.Open "Select * From Authors", "DSN=pubs;UID=sa;PWD=" Do Until rs.EOF Print rs!au_lname rs.MoveNext Loop rs.Close