Microsoft KB Archive/168335

From BetaArchive Wiki

Article ID: 168335

Article Last Modified on 3/2/2005



APPLIES TO

  • Microsoft ActiveX Data Objects 1.0
  • Microsoft ActiveX Data Objects 2.0
  • Microsoft ActiveX Data Objects 2.1
  • Microsoft ActiveX Data Objects 2.1 Service Pack 2
  • Microsoft ActiveX Data Objects 2.5
  • Microsoft ActiveX Data Objects 2.6
  • Microsoft ActiveX Data Objects 2.7
  • Microsoft Visual Basic 5.0 Learning Edition
  • Microsoft Visual Basic 6.0 Learning Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic 6.0 Enterprise Edition



This article was previously published under Q168335

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. There are many native OLE-DB Providers as well as an OLE-DB Provider for ODBC.

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, using MSDASQL (the Microsoft OLE-DB provider for ODBC).
  • 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.

The next two items were new in 2.5:

  • Stream: Provides the means to read or write binary information or text.
  • Record: Can represent a row in a recordset or a directory or a file.

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 Computer

To properly install ADO on your computer, you need to install MDAC. This installs both ADO and necessary underlying ADO components. OLE-DB also requires ODBC version 3.0 or later components.

MDAC is available free for download from the Web at the following URL:

After ADO is installed on your computer, create a new project inside Visual Basic. From the Projects menu, choose References, and then select Microsoft ActiveX Data Objects Library.

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 Visual Basic Error object as well as the ADO Errors collection.

ADO vs. DAO

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

   Dim r as recordset
                

You may receive the following error message:

runtime error 13: datatype mismatch


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:

167957 INFO: Extracting Error Information from ADO in VB


Keywords: kbinfo kbdatabase KB168335