ADO Tutorial

Microsoft ActiveX Data Objects (ADO)

ADO Tutorial

This tutorial illustrates how to use the ADO programming model to query and update a data source. First, it describes the steps necessary to accomplish this task. Then, the tutorial is repeated in Microsoft Visual Basic; Microsoft Visual C++, featuring Visual C++ Extensions; and Microsoft Visual J++, featuring ADO for Windows Foundation Classes (ADO/WFC).

This tutorial is coded in different languages for two reasons:

  • The documentation for ADO assumes the reader codes in Visual Basic. This makes the documentation convenient for Visual Basic programmers, but less useful for programmers who use other languages.

  • If you are uncertain about a particular ADO feature and you know a little of another language, you may be able to resolve your question by looking for the same feature expressed in another language.

How the Tutorial is Presented

This tutorial is divided into steps that correspond to the ADO programming model. Each step is discussed and illustrated with a fragment of Visual Basic code. At the end of the tutorial, all the code fragments are integrated into a Visual Basic example.

The integrated example is then repeated in other programming languages. Each step in each programming language example is numbered. Use the number of the step to refer to the corresponding discussion in this descriptive tutorial.

The ADO programming model is stated below. Use it as a roadmap as you proceed through the tutorial.

ADO Programming Model with Objects

  • Make a connection to a data source (Connection). Optionally, begin a transaction.

  • Optionally, create an object to represent an SQL command (Command).

  • Optionally, specify columns, tables, and values in the SQL command as variable parameters (Parameter).

  • Execute the command (Command, Connection, or Recordset).

  • If the command is row-returning, store the rows in a storage object (Recordset).

  • Optionally, create a view of the storage object so that you can sort, filter, and navigate the data (Recordset).

  • Edit the data, either adding, deleting, or changing rows and columns (Recordset).

  • If appropriate, update the data source with changes from the storage object (Recordset).

  • If a transaction was used, accept or reject the changes made during the transaction. End the transaction (Connection).

Next   Step 1: Open a Connection