SQL Query Using ADODataSet
Summary: These instructions show how to
use an ADODataSet component and an SQL Query to connect with a dBase database.
This Tech Note fills in many details for "A Practical ADO
Primer" example in Mastering
Delphi 5, pp. 562-565.
A. Verify DBF Table Exists
- Start Delphi 5
- Tools | Database Desktop
- File | Open | Table | C:\Program Files\Common Files\Borland Shared\Data\clients.DBF
| Open

- Scroll all the way to the right to view the last two columns: INTERESTS and IMAGE. The
IMAGE fields are all <BLOB Binary>.
- Close Database Desktop
B. Open DBF Table Using ADODataSet and
SQL Query
- Start Delphi 5 (if necessary)
- In the Object Inspector for Form, set these properties:
Caption: MD5 ADO Primer
Name: FormADOPrimer
Position: poScreenCenter
Height: 300
Width: 500
- File | New | Data Module | OK
Change name from DataModule2 to DataModuleClients
- File | Save Project As | Save in: C:\Temp (or other desired directory) |
ScreenADOPrimer.pas (instead of unit1.pas) | Save |
DataClients.pas (instead of unit2.pas) | Save |
ADOPrimer.dpr (instead of project1.dpr) | Save
- With the Components Tab visible and selected on the DataModuleClients
"form," select the ADO tab on the VCL palette. Double click on the ADOConnection
icon to add an instance to the form. Configure ADOConnection1 with these
properties:
Name: ADOConnection
Login Prompt: False
- Double click on the ellipses in the Connection String entry area. Select Use
Connection String and press the Build button.

(Same as Figure 12.1, Mastering Delphi
5, p. 563)
- Select Microsoft OLE DB Provider for ODBC Drivers.

- Select the Next button.
- Select the Use connection string radio button and select the Build button:

(Same as Figure 12.2, Mastering Delphi
5, p. 563)
- Select dBASE Files (not shared) and the OK button on this screen:

- On the Select Directory dialog, choose the directory
C:\Program Files\Common Files\Borland Shared\Data

- Select the OK button.

- Select the Test Connection button. This should be the result:

- Select the OK button three times.
- From the ADO VCL tab, double click on the ADODataset to place an instance
on DataModuleClients. Specify the following properties:
Name: ADODataSet
Connection: ADOConnection
CommandType: cmdText
- Double click on the Command Text property. Select "*" from the Fields
list and the Add Field to SQL button. Select clients from Tables and
the Add Table to SQL button. (This sure seems like a lot of work to save a few
keystrokes.)

(Similar to Figure 12.3, Mastering Delphi
5, p. 565)
- Select the OK button.
- From the Data Access tab on the VCL Palette, double click on the Data Source
icon. Configure DataSource1 to have these properties:
Name: DataSourceClients
DataSet: ADODataSet
- Select the Data Diagram tab on DataModuleClients. From the tree view of DataModuleClients,
drag each of these icons to the Data Diagram area: ADOConnection, ADODataSet,
DataSourceClients. Rearrange and resize the Data Diagram boxes as necessary.

(Similar to Figure 12.4, Mastering Delphi
5, p. 565)
- From View Unit, select ScreenADOPrimer and the OK button.
- In the Implementation section of ScreenADOPrimer, add "USES
DataClients;"
(This statement allows the items on the DataModuleClients to be used via the
IDE.)
- Select Toggle Form / Unit.
- From the Data Controls tab on the VCL Palette, double click on the DBGrid
icon to place an instance on FormADOPrimer. Configure DBGrid1 with the
following properties:
Name: DBGridClients
DataSource: DataModuleClients.DataSourceClients
Options.dgRowSelect: TRUE
- From the Data Controls tab on the VCL Palette, double click on the DBNavigator
icon to place an instance on FormADOPrimer. Configure DBNavigator1 with the
following properties:
Name: DBNavigatorClients
DataSource: DataModuleClients.DataSourceClients
- Select View Unit. Select DataClients. Select OK button. Select Toggle
Form/Unit. Select icon for ADODataSet. In the object inspector, set Active =
TRUE.
- Select View Unit. Select ScreenADOPrimer. Select OK button. Select Toggle
Form/Unit. Verify data are shown in design mode:

- Select Project | Build ADOPrimer | Run

- Use the DBNavigator and scroll bars to view and manipulate the data.
- Scroll all the way to the right-most columns. Note that the last column is INTERESTS and
that the IMAGE column is missing.
- Exit the program.
- File | Close All | Yes (to "Save Changes")
Links Verified 26 Jan 2000
Updated 18 Feb 2002

since 26 Jan 2000