RAD Studio for Microsoft .NET
ContentsIndex
PreviousUpNext
Building a VCL Forms dbExpress.NET Database Application

The following procedures describe how to build a dbExpress database application.  

Building a VCL Forms dbExpress.NET application consists of the following major steps:

  1. Set up the database connection.
  2. Set up the unidirectional 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 a dbExpress connection component

  1. Choose FileNewVCL Forms Application. The VCL Forms Designer displays.
  2. From the dbExpress category of the Tool Palette, place a TSQLConnection component on the form.
  3. Double-click the TSQLConnection component to display the Connection Editor.
  4. In the Connection Editor, set the Connection Name list to IBConnection.
  5. In the Connections Setting box, specify the path to the InterBase database file called employee.gdb in the Database field. By default, the file is located in C:\Program Files\Common Files\CodeGear Shared\Data.
  6. Accept the value in the User_Name field (sysdba) and Password field (masterkey).
  7. To test the connection, click the button with the checkmark on it (just above the Connection Name list).
    Note: By default, you are prompted to log in. Use the masterkey password. If the connection works a confirmation message appears. If you cannot connect to the database, make sure you have installed Interbase and that the server is started.
  8. Click OK to close the Connection Editor and save your changes.

To set up the unidirectional dataset

  1. From the dbExpress category of the Tool Palette, place a TSQLDataSet component at the top of the form.
  2. In the Object Inspector, set the SQLConnection property drop-down list to SQLConnection1.
  3. Set the CommandText to a SQL command, for example, Select * from sales. For the SQL command, you can either type a Select statement in the Object Inspector or click the ellipsis 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 Command Text Editor
    , click the Help button or press F1.
  4. In the Object Inspector, set the Active property to True to open the dataset.

To add the provider

  1. From the Data Access category of the Tool Palette, place a TDataSetProvider component at the top of the form.
  2. In the Object Inspector, set the DataSet property drop-down list to SQLDataSet1.

To add client dataset

  1. From the Data Access category of the Tool Palette, place a TClientDataSet component to the right of the DataSetProvider component on the form.
  2. In the Object Inspector, set the ProviderName drop-down 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, place a TDataSource component to the right of the ClientDataSet on the form.
  2. In the Object Inspector, set the DataSet property drop-down to ClientDataSet1.

To connect a DataGrid to the DataSet

  1. From the Data Controls category of the Tool Palette, place a TDBGrid component on the form.
  2. In the Object Inspector, set the DataSource property drop-down to DataSource1.
  3. Save all files in the project.
  4. Select RunRun. You are prompted to enter a password.
  5. Enter masterkey as the password. The application compiles and displays a VCL.NET form with a DBGrid.

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