Using a query component: an overview

From InterBase
Jump to: navigation, search

Go Up to Working with Queries


To use a query component in an application, follow these steps at design time:

  1. Place a query component from the InterBase tab of the Tool Palette in a data module, and set its Name property appropriately for your application.
  2. Set the Database property of the component to the name of the TIBDatabase component to query.
  3. Set the Transaction property of the component to the name of the TIBTransaction component to query.
  4. Specify a SQL statement in the SQL property of the component, and optionally specify any parameters for the statement in the Params property. For more information, see Specifying the SQL property at design time.
  5. If the query data is to be used with visual data controls, place a data source component from the Data Access tab of the Tool Palette in the data module, and set its DataSet property to the name of the query component. The data source component is used to return the results of the query (called a result set) from the query to data-aware components for display. Connect data-aware components to the data source using their DataSource and DataField properties.
  6. Activate the query component. For queries that return a result set, use the Active property or the Open method. For queries that only perform an action on a table and return no result set, use the ExecSQL method.

Executing the query:

To execute a query for the first time at runtime, follow these steps:

  1. Close the query component.
  2. Provide a SQL statement in the SQL property if you did not set the SQL property at design time, or if you want to change the SQL statement already provided. To use the design-time statement as is, skip this step. For more information about setting the SQL property, see Specifying the SQL statement to execute.
  3. Set parameters and parameter values in the Params property either directly or by using the ParamByName method. If a query does not contain parameters, or the parameters set at design time are unchanged, skip this step. For more information about setting parameters, see Setting parameters.
  4. Call Prepare to bind parameter values into the query. Calling Prepare is optional, though highly recommended. For more information about preparing a query, see Preparing a query.
  5. Call Open for queries that return a result set, or call ExecSQL for queries that do not return a result set. For more information about opening and executing a query, see Executing a query.

After you execute a query for the first time, then as long as you do not modify the SQL statement, an application can repeatedly close and reopen or re-execute a query without preparing it again. For more information about reusing a query, see Executing a query.

Advance To: