ADO (ActiveX Data Objects)

ADOExpress Step-by-Step-from-Scratch Tech Note


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
B.  Open DBF Table Using ADODataSet and SQL Query

A.  Verify DBF Table Exists

  1. Start Delphi 5
  2. Tools | Database Desktop
  3. File | Open | Table | C:\Program Files\Common Files\Borland Shared\Data\clients.DBF | Open
  4. Scroll all the way to the right to view the last two columns: INTERESTS and IMAGE. The IMAGE fields are all <BLOB Binary>.
  5. Close Database Desktop

 


B.  Open DBF Table Using ADODataSet and SQL Query

  1. Start Delphi 5 (if necessary)
  2. In the Object Inspector for Form, set these properties:
    Caption: MD5 ADO Primer
    Name: FormADOPrimer
    Position: poScreenCenter
    Height: 300
    Width: 500
  3. File | New | Data Module | OK
    Change name from DataModule2 to DataModuleClients
  4. 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
  5. 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
  6. Double click on the ellipses in the Connection String entry area. Select Use Connection String and press the Build button.
  7. (Same as Figure 12.1, Mastering Delphi 5, p. 563)

  8. Select Microsoft OLE DB Provider for ODBC Drivers.
  9. Select the Next button.
  10. Select the Use connection string radio button and select the Build button:
  11. (Same as Figure 12.2, Mastering Delphi 5, p. 563)

     

  12. Select dBASE Files (not shared) and the OK button on this screen:
  13.  

  14. On the Select Directory dialog, choose the directory
    C:\Program Files\Common Files\Borland Shared\Data
  15. Select the OK button.
  16. Select the Test Connection button. This should be the result:
  17. Select the OK button three times.
  18. 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
  19. 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.)
  20. (Similar to Figure 12.3, Mastering Delphi 5, p. 565)

  21. Select the OK button.
  22. 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
  23. 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.

  24. (Similar to Figure 12.4, Mastering Delphi 5, p. 565)

  25. From View Unit, select ScreenADOPrimer and the OK button.
  26. In the Implementation section of ScreenADOPrimer, add "USES DataClients;"
    (This statement allows the items on the DataModuleClients to be used via the IDE.)
  27. Select Toggle Form / Unit.
  28. 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
  29. 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
  30. Select View Unit. Select DataClients. Select OK button. Select Toggle Form/Unit. Select icon for ADODataSet. In the object inspector, set Active = TRUE.
  31. Select View Unit. Select ScreenADOPrimer. Select OK button. Select Toggle Form/Unit. Verify data are shown in design mode:
  32. Select Project | Build ADOPrimer | Run
  33. Use the DBNavigator and scroll bars to view and manipulate the data.
  34. Scroll all the way to the right-most columns. Note that the last column is INTERESTS and that the IMAGE column is missing.
  35. Exit the program.
  36. File | Close All | Yes (to "Save Changes")

 


Links Verified 26 Jan 2000
Updated 18 Feb 2002


since 26 Jan 2000