RAD Studio for Microsoft .NET |  |

Building a VCL.NET Forms ADO.NET Database Application
See Also
Collapse All

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:

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 FileNewOtherDelphi for .NET ProjectsVCL Forms Application. The VCL Forms Designer displays.
2. From the dbGO category of the Tool Palette, place a TADOConnection component on the form.
3. Double-click the TADOConnection component to display the ConnectionString dialog.
4. If necessary, select Use Connection String; then click the Build button to display the Link Properties dialog box.
5. 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.
6. 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.
7. If it is not already filled in, enter Admin in the User name field and select the Blank password check box.
8. Click Test Connection to confirm the connection. A dialog appears, indicating the status of the connection.
9. Click OK twice to close the Data Link Properties dialog box and the ConnectionString dialog box.

To set up the dataset

1. From the dbGO category, double-click a TADODataSet component to place it on the form.
2. In the Object Inspector, set the Connection property drop-down list from the Linkages category to ADOConnection1.
3. 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.
4. Set the Active property to True to open the dataset. You are prompted to log in.
5. Enter Admin for the username.
6. Leave the password field blank.

To add the provider

1. From the Data Access category of the Tool Palette, double-click a TDataSetProvider component to place it at the top of the form.
2. In the Object Inspector, set the DataSet property to ADODataSet1.

To add client dataset

1. 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.
2. In the Object Inspector, set the ProviderName property 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. 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.
2. In the Object Inspector, set the DataSet property to ClientDataSet1.

To connect a DataGrid to the DataSet

1. From the Data Controls area of the Tool Palette, double-click a TDBGrid component to place it on the form.
2. In the Object Inspector, set the DataSource property to DataSource1.
3. SelectRunRun. You are prompted to log in.
4. Enter Admin for the username.
5. Leave the password field blank.
6. Click OK. The application compiles and displays a VCL form with a DBGrid.

See Also

VCL.NET Overview

Building a VCL Forms dbExpress.NET Database Application

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!