AnyDAC
ContentsIndexHome
PreviousUpNext
TADDataSet.ApplyUpdates Method

Applies changes for all records in the dataset change log to the database.

Group
Links
Parameters 
Description 
AMaxErrors: Integer = -1 
A maximum number of allowed errors. Default value is -1. 

The number of errors is encountered.

Use ApplyUpdates to apply changes for all records in the dataset change journal to the database. 

This method is useful when CachedUpdates = True mode. The ApplyUpdates call performs the steps:

  1. Fires a BeforeApplyUpdates event.
  2. Calls the data adapter to generate / use SQL update commands for each row and post changes to the database.
  3. Fires an AfterApplyUpdates event.
  4. Calls the dataset's Reconcile method to reconcile any records that has errors in step 2.
  5. If there were no errors, then calls CommitUpdates for the TADCustomMemTable descendants. For the TADRdbmsDataSet descendants (TADQuery, TADStoredProc, TADTable, etc), application should call Reconcile and CommitUpdates explicitly.

AMaxErrors indicates the maximum number of errors that the AnyDAC should allow before prematurely stopping the update operation. Set AMaxErrors to –1 to indicate that there is no limit to the number of errors, or to 0 to indicate that no error is allowed. 

ApplyUpdates returns the number of errors it encountered. Based on this return value and the setting of AMaxErrors, successfully applied records are removed from the dataset's change log. If the update process is aborted before all updates are applied, any unapplied updates remain in the change log. 

ApplyUpdates does not raise exception. Instead application should review erroneous records using Reconcile and OnReconcileError event handler, or FilterChanges and RowError properties. Read "Reviewing errors" at Caching Updates for more details. 

All changes are applied in the dataset modifications order. First modification (insert / update / delete) will be applied first, last modification will be applied last.

function ApplyUpdates(AMaxErrors: Integer = -1): Integer;
procedure TForm1.btnApplyClick(ASender: TObject);
begin
  if ADStoredProc1.UpdatesPending then
    ADStoredProc1.ApplyUpdates;
end;

See AnyDAC\Samples\Comp Layer\TADMemTable\CachedUpdates sample for details.

What do you think about this topic? Send feedback!