beginners tutorial - Learn VB6
VB6 tutorial - Learn Advanced VB6
Analysis - System analysis and Design tutorial for Software Engineering
You are here: Visual
Basic > Advanced VB6 tutorial
> Chapter 8
Setting Up the ADO Data Control in Visual Basic 6 (VB6)
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
8.5 Creating an ADO Data Control
Add the Microsoft ADO DataControl 6.0 (OLEDB) from the Project, Components
menu dialog box, as in Figure 8.13. The ADO Data Control icon should now appear
in the VB toolbox.
FIGURE 8.13 Adding the Microsoft ADO Data Control to your project's components.
Place an instance of the ADO Data Control on the form (see Figure 8.14).
FIGURE 8.14. Placing an instance of the ADO Data Control on a form.
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.)
Set the ConnectionString property using steps 5–9.
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 in Figure 8.15.
FIGURE 8.15 The first and only Property Page dialog box for the ADO Data Control's
As Source of Connection, choose one of the following three options:
• Use 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 (see Figure 8.16).
FIGURE 8.16 Choosing a provider for the ADO Data Control's ConnectionString
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 of the Microsoft Jet 3.51 OLE DB, you are prompted to choose an Access data
file and set some security options (see Figure 8.17).
FIGURE 8.17 Setting up connection information for the Jet provider
Click OK to accept the ConnectionString options you have built.
Still in the ADO Data Control's Properties window, navigate to the RecordSource
property and click the ellipsis button.
On the RecordSource tab (see Figure 8.18) of the resulting Property Page dialog
box, choose the CommandType (adCmdUnknown, adCmdText, adCmdTable, adCmdStoredProc).
FIGURE 8.18. The Property Page dialog box for an ADO Data Control's RecordSource
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 (see Figure 8.19).
FIGURE 8.19 A valid Select statement as command text for the RecordSource
• 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
(see Figure 8.20).
FIGURE 8.20. A table or stored procedure name for the RecordSource property.
Click OK to end the RecordSource dialog box.
After you have set the ADO Data
Control up to expose a Recordset, you can bind
VB controls to the ADO Data Control, as discussed
in the following sections.
NOTE - Additional ADO Data Control Properties
That Affect the Recordset: You will eventually need to fine-tune the
Recordset's behavior by setting the CursorLocation, CursorType, and Locktype properties.
These properties correspond to the standalone Recordset object's properties of
the same name. The next chapter discusses these properties and their meaning in
<< Previous | Contents
| Next >>