Page 252 - Open Soource Technologies 304.indd
P. 252
Event Driven Programming
DAO Performs Better Than ADO When Accessing Jet Databases When accessing
Jet databases (that is, MS Access), DAO will perform better than ADO, because
DAO was optimized for Jet.
11.3.1 Opening a Database with an ADO Data Control
To add a new ADO data control to a form, follow these steps:
1. Select the Project\Components menu item.
2. Click the Controls tab in the Components dialog box that opens.
3. Select the Microsoft ADO Data Control entry in the Controls list box.
4. Click on OK to close the Components dialog box.
5. This adds the ADO data control tool to the toolbox; draw that control as you want it on
your form.
6. Connect the ADO data control’s Connection object to a data source with the ConnectionString
property, separating items in that string with semicolons. At the least, you should specify
the Provider (the type of OLE DB) and Data Source (database name) values in the
ConnectionString.
Let’s see an example. Here, we’ll connect an ADO data control to the database we’ve
constructed in the early parts of this chapter, db.mdb. To do that, add an ADO data control,
Adodc1, to a form, and set its ConnectionString property to specify the data provider type
and the data source for that database like this:
“PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=c:\vbbb\ado\db.mdb;”
One way of connecting an ADO control to a database easily is with the Data
Form Wizard, which generates the connection string for you automatically.
Next, set the ADO data control’s RecordSource property to the table to work with, which is
students in our example database, db.mdb.
Now you’ve connected a database to the ADO data control. To connect the ADO data control to
bound controls.
11.3.2 The ADO Data-Bound Controls
There are three data-bound controls that are specially optimized for use with the ADO data
control: DataGrid controls, DataCombo controls, and DataList controls (don’t confuse these
controls with the non-ADO optimized data-bound controls like the DBCombo and DBList controls).
These controls are specifically designed to work with ADO data controls and won’t work with
standard controls like the data control.
To add these controls to a program, follow these steps:
1. Select the Project\Components menu item.
2. Click the Controls tab in the Components dialog box that opens.
3. Select both the Microsoft DataGrid Control entry and the Microsoft DataList Controls entry
in the Controls list box.
4. Click on OK to close the Components dialog box.
246 LOVELY PROFESSIONAL UNIVERSITY