The following procedure describes how to build an ADO.NET database application.
Building a VCL.NET ADO.NET 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 FileNewOtherDelphi for .NET ProjectsVCL Forms Application. The VCL Forms Designer displays.
- From the dbGO category of the Tool Palette, place a TADOConnection component on the form.
- Double-click the TADOConnection component to display the ConnectionString dialog.
- If necessary, select Use Connection String; then click the Build button to display the Link Properties dialog box.
- On the Provider page of the dialog, select Microsoft Jet 4.0 OLE DB Provider; then click the Next button to display the Connections page.
- On the Connections page, click the ellipsis button to browse for the dbdemos.mdb database. The default path to this database is C:\Program Files\Common Files\Borland Shared\Data.
- If it is not already filled in, enter Admin in the User name field and select the Blank password check box.
- Click Test Connection to confirm the connection. A dialog appears, indicating the status of the connection.
- Click OK twice to close the Data Link Properties dialog box and the ConnectionString dialog box.
To set up the dataset
- From the dbGO category, double-click a TADODataSet component to place it on the form.
- In the Object Inspector, set the Connection property drop-down list from the Linkages category to ADOConnection1.
- Set the CommandText to an SQL command, for example, Select * from orders. You can either type the Select statement in the Object Inspector or click the ellipsis button to the right of CommandText to display the Command Text Editor where you can build your own query statement.
Tip: If you need additional help while using the CommandText Editor
, click the Help button or press F1.
- Set the Active property to True to open the dataset. You are prompted to log in.
- Enter Admin for the username.
- Leave the password field blank.
To add the provider
- From the Data Access category of the Tool Palette, double-click a TDataSetProvider component to place it at the top of the form.
- In the Object Inspector, set the DataSet property to ADODataSet1.
To add client dataset
- From the Data Access category of the Tool Palette, double-click a TClientDataSet component to place it to the right of the DataSetProvider component on the form.
- In the Object Inspector, set the ProviderName property 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
- From the Data Access category of the Tool Palette, double-click a TDataSource component to place it to the right of the ClientDataSet on the form.
- In the Object Inspector, set the DataSet property to ClientDataSet1.
To connect a DataGrid to the DataSet
- From the Data Controls area of the Tool Palette, double-click a TDBGrid component to place it on the form.
- In the Object Inspector, set the DataSource property to DataSource1.
- SelectRunRun. You are prompted to log in.
- Enter Admin for the username.
- Leave the password field blank.
- Click OK. The application compiles and displays a VCL form with a DBGrid.