Applying Cached Updates with a Database Component Method
Go Up to Applying Cached Updates
Ordinarily, applications cache updates at the dataset level. However, there are times when it is important to apply the updates to multiple interrelated datasets in the context of a single transaction. For example, when working with master/detail forms, you will likely want to commit changes to master and detail tables together.
To apply cached updates to one or more datasets in the context of a database connection, call the database component’s ApplyUpdates
method. The following code applies updates to the CustomersQuery
dataset in response to a button click event:
procedure TForm1.ApplyButtonClick(Sender: TObject); begin IBDatabase1.ApplyUpdates([CustomersQuery]); end;
The above sequence starts a transaction, and writes cached updates to the database. If successful, it also commits the transaction, and then commits the cached updates. If unsuccessful, this method rolls back the transaction, and does not change the status of the cached updates. In this latter case, your application should handle cached update errors through a dataset’s OnUpdateError
event. For more information about handling update errors, see Handling Cached Update Errors.
The main advantage to calling a database component’s ApplyUpdates
method is that you can update any number of dataset components that are associated with the database. The parameter for the ApplyUpdates
method for a database is an array of TIBCustomDataSet
. For example, the following code applies updates for two queries used in a master/detail form:
IBDatabase1.ApplyUpdates([CustomerQuery, OrdersQuery]);
For more information about updating master/detail tables, see Applying Updates for Master/detail Tables.