Show: Delphi C++
Display Preferences

Building a VCL Forms ADO Database Application

From RAD Studio
Jump to: navigation, search

Go Up to How To Build VCL Forms Applications


The following procedure describes how to build an ADO database application.

Building a VCL ADO application consists of the following major steps:

  1. Set up the database connection.
  2. Set up the dataset.
  3. Set up the data provider, client dataset, and data source.
  4. Connect a DataGrid to the connection components.
  5. Run the application.

To add an ADO connection component:

  1. Choose File > New > Other > Delphi Projects or C++Builder Projects and double-click the VCL Forms Application icon.The VCL Forms Designer is displayed.
  2. From the dbGo page of the Tool Palette, place an ADOConnection component on the form.
  3. Double-click the ADOConnection component to display the ConnectionString dialog.
  4. If necessary, select Use Connection String; then click the Build button to display the Data Link Properties dialog.
  5. On the Provider page of the dialog, select Microsoft Jet 4.0 OLE DB Provider; then click the Next button to display the Connection page.
  6. On the Connection page, click the ellipsis button to browse for the dbdemos.mdb database. The default path to this database is C:\Program Files\Common Files\Embarcadero Shared\Data.
  7. Click Test Connection to confirm the connection. A dialog appears, indicating the status of the connection.
  8. Click OK to close the Data Link Properties dialog. Click OK to close the ConnectionString dialog.

To set up the dataset:

  1. From the dbGo page, place an ADODataSet component at the top of the form.
  2. In the Object Inspector, select the Connection property drop-down list. Set it to ADOConnection1.
  3. Set the CommandText property to an SQL command, for example, Select * from orders. You can either type the Select statement in the Object Inspector or click the ellipsis to the right of CommandText to display the CommandText Editor where you can build your own query statement.
    Tip: If you need additional help while using the CommandText Editor, click the Help button.
  4. Set the Active property to True to open the dataset.You are prompted to log in. Use admin for the username and no password.

To add the provider:

  1. From the Data Access page, place a DataSetProvider component at the top of the form.
  2. In the Object Inspector, select the DataSet property drop-down list. Set it to ADODataSet1.

To add client dataset:

  1. From the Data Access page, place a ClientDataSet component to the right of the DataSetProvider component on the form.
  2. In the Object Inspector, select the ProviderName drop-down. Set it to DataSetProvider1.
  3. Set the Active property to True to allow data to be passed to your application.A data source connects the client dataset with data-aware controls. Each data-aware control must be associated with a data source component to have data to display and manipulate. Similarly, all datasets must be associated with a data source component for their data to be displayed and manipulated in data-aware controls on the form.

To add the data source:

  1. In the Tool Palette on the Data Access page, place a DataSource component to the right of the ClientDataSet on the form.
  2. In the Object Inspector, select the DataSet property drop-down. Set it to ClientDataSet1.

To connect a DataGrid to the DataSet:

  1. In the Tool Palette on the Data Controls page, place a DBGrid component on the form.
  2. In the Object Inspector, select the DataSource property drop-down. Set the data source to DataSource1.
  3. Choose Run > Run.
  4. You are prompted to log in. Enter admin for the username and no password.The application compiles and displays a VCL form with a DBGrid.

See Also

Personal tools
In other languages
Previous Versions
Assistance