Building a VCL Forms ADO Database Application
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:
- Set up the database connection.
- Set up the dataset.
- Set up the data provider, client dataset, and data source.
- Connect a DataGrid to the connection components.
- Run the application.
To add an ADO connection component:
- Choose File > New > Other > Delphi Projects or C++Builder Projects and double-click the VCL Forms Application icon.The VCL Forms Designer is displayed.
- From the dbGo page of the Tool Palette, place an ADOConnection component on the form.
- Double-click the ADOConnection component to display the ConnectionString dialog.
- If necessary, select Use Connection String; then click the Build button to display the Data Link Properties dialog.
- 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.
- 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.
- Click Test Connection to confirm the connection. A dialog appears, indicating the status of the connection.
- Click OK to close the Data Link Properties dialog. Click OK to close the ConnectionString dialog.
To set up the dataset:
- From the dbGo page, place an ADODataSet component at the top of the form.
- In the Object Inspector, select the Connection property drop-down list. Set it to ADOConnection1.
- 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.
- 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:
- From the Data Access page, place a DataSetProvider component at the top of the form.
- In the Object Inspector, select the DataSet property drop-down list. Set it to ADODataSet1.
To add client dataset:
- From the Data Access page, place a ClientDataSet component to the right of the DataSetProvider component on the form.
- In the Object Inspector, select the ProviderName drop-down. Set it to DataSetProvider1.
- 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:
- In the Tool Palette on the Data Access page, place a DataSource component to the right of the ClientDataSet on the form.
- In the Object Inspector, select the DataSet property drop-down. Set it to ClientDataSet1.
To connect a DataGrid to the DataSet:
- In the Tool Palette on the Data Controls page, place a DBGrid component on the form.
- In the Object Inspector, select the DataSource property drop-down. Set the data source to DataSource1.
- Choose Run > Run.
- 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.