RAD Studio |  |

Using Multiple Update Objects
See Also
Collapse All

The Borland Database Engine (BDE) has been deprecated, so it will not be enhanced. For instance, BDE will never have Unicode support. You should not undertake new development with BDE. Consider migrating your existing database applications from BDE to dbExpress.

When more than one base table referenced in the update dataset needs to be updated, you need to use multiple update objects: one for each base table updated. Because the dataset component's UpdateObject only allows one update object to be associated with the dataset, you must associate each update object with a dataset by setting its DataSet property to the name of the dataset.

Tip: When using multiple update objects, you can use TBDEClientDataSet instead of TClientDataSet with an external provider. This is because you do not need to set the source dataset's UpdateObject property.
The DataSet property for update objects is not available at design time in the Object Inspector. You can only set this property at runtime.
Copy Code

    UpdateSQL1.DataSet := Query1;

Copy Code

    UpdateSQL1->DataSet = Query1;

The update object uses this dataset to obtain original and updated field values for parameter substitution and, if it is a BDE-enabled dataset, to identify the session and database to use when applying the updates. So that parameter substitution will work correctly, the update object's DataSet property must be the dataset that contains the updated field values. When using the BDE-enabled dataset to cache updates, this is the BDE-enabled dataset itself. When using a client dataset, this is a client dataset that is provided as a parameter to the BeforeUpdateRecord event handler.

When the update object has not been assigned to the dataset's UpdateObject property, its SQL statements are not automatically executed when you call ApplyUpdates. To update records, you must manually call the update object from an OnUpdateRecord event handler (when using the BDE to cache updates) or a BeforeUpdateRecord event handler (when using a client dataset). In the event handler, the minimum actions you need to take are

- If you are using a client dataset to cache updates, you must be sure that the updates object's DatabaseName and SessionName properties are set to the DatabaseName and SessionName properties of the source dataset.
- The event handler must call the update object's ExecSQL or Apply method. This invokes the update object for each record that requires updating. For more information about executing update statements, see Executing the SQL statements.
- Set the event handler's UpdateAction parameter to uaApplied (OnUpdateRecord) or the Applied parameter to True (BeforeUpdateRecord).

You may optionally perform data validation, data modification, or other operations that depend on each record's update.
Warning: If you call an update object's ExecSQL or Apply method in an OnUpdateRecord event handler, be sure that you do not set the dataset's UpdateObject property to that update object. Otherwise, this will result in a second attempt to apply each record's update.
Topics

Name | Description
Calling the Apply Method | The Apply method for an update component manually applies updates for the current record. There are two steps involved in this process: Initial and edited field values for the record are bound to parameters in the appropriate SQL statement. The SQL statement is executed. Call the Apply method to apply the update for the current record in the update cache. The Apply method is most often called from within a handler for the dataset's OnUpdateRecord event or from a provider's BeforeUpdateRecord event handler. Warning: If you use the dataset's UpdateObject property to associate dataset and update object, Apply is called... more
Executing the SQL Statements | When you use multiple update objects, you do not associate the update objects with a dataset by setting its UpdateObject property. As a result, the appropriate statements are not automatically executed when you apply updates. Instead, you must explicitly invoke the update object in code. There are two ways to invoke the update object. Which way you choose depends on whether the SQL statement uses parameters to represent field values: If the SQL statement to execute uses parameters, call the Apply method. If the SQL statement to execute does not use parameters, it is more efficient to call... more

See Also

Creating SQL Statements for Update Components

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!