Icon DataSource Property

property DataSource: TDataSource

Usage

The DataSource property specifies the TDataSource component from which to extract current column values to use in the identically-named parameters in the query's SQL statement specified via the SQL property. This allows you to automatically fill parameters in a query with column values from another data source. Parameters that have the same name as columns in the other data source are filled with the column values. Parameters with names that are not the same as columns in the other dataset do not automatically get values, and must be set by the application manually.

DataSource must point to a TDataSource component linked to another dataset component, meaning that it cannot point to this TEDBQuery component. The dataset specified in the TDataSource component's DataSet property must be created, populated, and opened before attempting to bind parameters. Parameters are bound by calling the Prepare method prior to executing the query using the ExecSQL or Open method. If the SQL statement used by the query does not contain parameters, or all parameters are bound by the application using the Params property or the ParamByName method, the DataSource property need not be assigned.

If the SQL statement specified in the SQL property of the TEDBQuery component is a SELECT statement, the query is executed using the new column values each time the row pointer in the other data source is changed. It is not necessary to call the Open method of the TEDBQuery component each time. This makes using the DataSource property to dynamically modify WHERE clause conditions useful for establishing master-detail relationships. Set the DataSource property in the detail query to the TDataSource component for the master data source.

Information If the SQL statement contains parameters with the same name as columns in the other dataset, do not manually set values for these parameters. Any values manually set, either by using the Params property or the ParamByName method, will be overridden with automatic values.
Image