Saturday, August 30, 2014

Setting Up the ADO Data Control

To create an ADO Data Control that exposes a Recordset in your application, at the minimum you need to do the following:
  • Specify a Connection by filling in the ConnectionString property.
  • Specify how to derive a Recordset by setting the RecordSource property (which is a complex property requiring its own dialog box to set up).
The detailed steps are as follows:

STEP BY STEP
Creating an ADO Data Control


  1. Add the Microsoft ADO DataControl 6.0 (OLEDB) from the Project, Components menu dialog box. The ADO Data Control icon should now appear in the VB toolbox.
Adding the Microsoft ADO Data Control to your project's components.
    2.  Place an instance of the ADO Data Control on the form.
 
Placing an instance of the ADO Data Control on a form.


3. Change the control's Name and Caption from their default values. (The Caption is for information only, so you can set it to whatever you think will be most informative for the user.) 

4. Set the ConnectionString property using steps 5–9.

5. Click the ellipsis next to the ConnectionString property in the ADO Data Control's Properties window to bring up the Property Page dialog box for this property, as shown below.



The first and only Property Page dialog box for the ADO Data Control's ConnectionString property.


6. As Source of Connection, choose one of the following three options:
  • Ese Data Link File. If you choose this option, you will be able to click the Browse button to specify an existing *.UDL file).
  • Use ODBC Data Source Name. If you choose this option, you will be able to choose an existing ODBC DSN from the drop-down list, or you can create a new DSN by clicking the New button.
  • Use Connection String. If you choose this option, you will be able to click the Build button to bring up the Data Link Properties tabbed dialog box. 


The following steps assume that you have chosen this option. 
 

On the Provider tab of the Data Link Properties tabbed dialog box, choose an OLE DB data provider, such as Microsoft Jet 3.51 OLE DB

Choosing a provider for the ADO Data Control's ConnectionString property.


7. The Connection tab of the Data Link Properties tabbed dialog box will vary in appearance, depending on the provider specified in the preceding step. In the case if the Microsoft Jet 3.51 OLE DB, you are prompted to choose an Access data file and set some security options.



Setting up connection information for the Jet provider
   

8.  Click OK to accept the ConnectionString options you have built.

9. Still in the ADO Data Control's Properties window, navigate to the RecordSource property and click the ellipsis button.

10. On the RecordSource tab (see Figure 8.18) of the resulting Property Page dialog box, choose the CommandType (adCmdUnknown, adCmdText, adCmdTable, adCmdStoredProc).




The Property Page dialog box for an ADO Data Control's RecordSource property.

  

11. Complete the dialog box appropriately for the CommandType that you chose:
  • If you chose adCmdText, fill in the text of a valid Select statement in the Command Text field



A valid Select statement as command text for the RecordSource property.
  •  If you chose adCmdTable or adCmdStoredProc, fill in the appropriate table or stored procedure     name in the Table or Stored Procedure Name drop-down list.
A table or stored procedure name for the RecordSource property.
12. Click OK to end the RecordSource dialog box.