Page 254 - Open Soource Technologies 304.indd
P. 254
Event Driven Programming
11.4 Data Base Access Using the ADO Data Control
Like a Data Environment, the ADO Data Control also simplifies, automates, or even eliminates
some data programming tasks. It has the following similarities to the Data Environment
Designer:
Both the Data Environment and the ADO Control expose a Recordset to the programmer.
Both the Data Environment and the ADO Control are used to bind VB controls (such as DataGrid
or TextBox controls) to a Recordset.
Both the Data Environment and the ADO Control enable you to determine the Recordset’s cursor
type, cursor location, locking strategy, and cache size.
When necessary, the programmer can bypass the automated user interface and directly manipulate
the Recordset in code. Recordset manipulation is the same in code for both the ADO Data Control
and the Data Environment, with but a single syntactic difference: You refer to the ADO Data
Control’s Recordset with the following syntax:
ADDataControlName.Recordset
You refer to the Data Environment’s Recordset with this syntax:
DataEnvironmentName.rsCommandName
The ADO Data Control differs in the following ways from a Data Environment, however:
The ADO Data Control supports only one Recordset at a time.
The ADO Data Control does not directly expose Command or Connection objects.
The ADO Data Control is visible at runtime and furnishes a visual navigation interface to the
user. The following sections discuss how to set up an ADO Data Control, how to manipulate it
programmatically, and how to bind controls to its Recordset.
11.4.1 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:
11.4.2 Creating an ADO Data Control
1. Add the Microsoft ADO DataControl 6.0 (OLEDB) from the Project, Components menu
dialog box, as in Figure 11.2. The ADO Data Control icon should now appear in the VB
toolbox.
2. Place an instance of the ADO Data Control on the form (see Figure 11.3).
248 LOVELY PROFESSIONAL UNIVERSITY