INFO: Using ActiveX Data Objects (ADO) via Visual Basic

Last reviewed: August 29, 1997
Article ID: Q168335
The information in this article applies to:
  • ActiveX Data Objects (ADO) used with: - Microsoft Visual Basic Learning, Professional, and Enterprise

         Editions for Windows, version 5.0
    

SUMMARY

This article discusses what is necessary to take advantage of ActiveX Data Objects (ADO) with Visual Basic.

MORE INFORMATION

What is ADO?

ActiveX Data Objects is a programming model, which means that it is not dependent upon any given back-end engine. Currently, however, the only engine supporting the ADO model is OLE-DB. OLE-DB is currently dependent on ODBC Version 3.0 Administrator and ODBC Drivers. This is accomplished through the OLE-DB Provider for ODBC, often referred to as Kagera. At present Kagera is the only released provider for OLE-DB, but like ODBC Drivers, other OLE-DB providers can be used seamlessly from ADO.

The ADO object model consists of six objects:

  • Connection: Represents an open connection, in this case to an OLE-DB datasource that can be an ODBC data source via Kagera.
  • Error: Contains details about data access errors, refreshed for each time an error occurs in a single operation involving ADO.
  • Command: Defines a specific command you wish to execute against data.
  • Parameters: Optional collection off the command object for any parameters you wish to provide to the command.
  • Recordset: Represents a set of records from a table, command object, or SQL Syntax. Can be created without any underlying Connection object.
  • Field: Represents a single column of data in a recordset.
  • Property: A collection of values raised by the provider for ADO.

ADO/R is a subset of this ADO object model used with the Advanced Data Connector that provides only the Recordset and Field objects.

Installing ADO on your Machine

To properly install ADO on your machine, you will need to install the OLE- DB SDK version 1.1+, Internet Information Server 3.0+, or Visual InterDev 1.0+. This will install both ADO and necessary underlying ADO components. OLE-DB also requires ODBC version 3.0 Components, which are normally installed from Visual C++.

The OLE-DB SDK is available free for download off the Web from http://www.microsoft.com/data/oledb/.

After ADO is installed on your machine, simply create a new project inside Visual Basic, go to the PROJECTS^REFERENCES menu and select the following:

   Microsoft OLE-DB ActiveX Data Objects (1.0) Library


Error Handling

The documentation for the ADO Error object indicates that the Errors Collection will be populated if any error occurs within ADO or its underlying provider. This is somewhat incorrect. Depending on the source of the error, ADO's errors collection may not be populated. You need to check both the VB Error object as well as the ADO Errors collection.

For more information see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q167957
   TITLE     : INFO: Extracting Error Information from ADO in VB

ADO vs. DAO

If you include references to both ADO and DAO in the same project, you will have some difficulty. Both use the same object named Recordset, so the following code is ambiguous:

   Dim r as recordset

To specify which object model you want to use, include a qualifier in front:

   Dim s As ADODB.Recordset
   Dim t As DAO.Recordset

REFERENCES

For more information, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q168342
   TITLE:      INFO: Choosing the Right VB5 Data Access Interface
               (ADO/DAO/RDO)

(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Don Willits, Microsoft Corporation
Keywords          : adoall adoengall adoengdb
Version           : 5.0
Platform          : WINDOWS
Issue type        : kbinfo


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.