Using a query component: an overview
Go Up to Working with Queries
To use a query component in an application, follow these steps at design time:
- Place a query component from the InterBase tab of the Tool Palette in a data module, and set its
Nameproperty appropriately for your application. - Set the
Databaseproperty of the component to the name of theTIBDatabasecomponent to query. - Set the
Transactionproperty of the component to the name of theTIBTransactioncomponent to query. - Specify a SQL statement in the
SQLproperty of the component, and optionally specify any parameters for the statement in theParamsproperty. For more information, see Specifying the SQL property at design time. - 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
DataSetproperty 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 theirDataSourceandDataFieldproperties. - Activate the query component. For queries that return a result set, use the
Activeproperty or theOpenmethod. For queries that only perform an action on a table and return no result set, use theExecSQLmethod.
Executing the query:
To execute a query for the first time at runtime, follow these steps:
- Close the query component.
- Provide a SQL statement in the
SQLproperty if you did not set theSQLproperty 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 theSQLproperty, see Specifying the SQL statement to execute. - Set parameters and parameter values in the
Paramsproperty either directly or by using theParamByNamemethod. 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. - Call
Prepareto bind parameter values into the query. CallingPrepareis optional, though highly recommended. For more information about preparing a query, see Preparing a query. - Call
Openfor queries that return a result set, or callExecSQLfor 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.