Using Query-type Datasets

From RAD Studio
Jump to: navigation, search

Go Up to Understanding Datasets Index

To use a query-type dataset

  1. Place the appropriate dataset component in a data module or on a form, and set its Name property to a unique value appropriate to your application.
  2. Identify the database server to query. Each query-type dataset does this differently, but typically you specify a database connection component:
    • For TQuery, specify a TDatabase component or a BDE alias using the DatabaseName property.
    • For TADOQuery, specify a TADOConnection component using the Connection property.
    • For TSQLQuery, specify a TSQLConnection component using the SQLConnection property.
    • For TIBQuery, specify a TIBConnection component using the Database property. For information about using database connection components, see Connecting to databases
  3. Specify an SQL statement in the SQL property of the dataset, and optionally specify any parameters for the statement.
  4. If the query data is to be used with visual data controls, add a data source component to the data module, and set its DataSet property to the query-type dataset. The data source component forwards the results of the query (called a result set) to data-aware components for display. Connect data-aware components to the data source using their DataSource and DataField properties.
  5. Activate the query component. For queries that return a result set, use the Active property or the Open method. To execute queries that only perform an action on a table and return no result set, use the ExecSQL method at run time. If you plan to execute the query more than once, you may want to call Prepare to initialize the data access layer and bind parameter values into the query. For information about preparing a query, see Preparing Queries.

In addition to the basic steps described above, the following topics describe how to establish master/detail relationships when using query-type datasets and how to improve performance when you only need a unidirectional cursor:

See Also