FireDAC.Comp.DataSet.TFDDataSet.ApplyUpdates
Delphi
function ApplyUpdates(AMaxErrors: Integer = -1): Integer;
C++
int __fastcall ApplyUpdates(int AMaxErrors = 0xffffffff);
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
function | public | FireDAC.Comp.DataSet.pas FireDAC.Comp.DataSet.hpp |
FireDAC.Comp.DataSet | TFDDataSet |
Description
Applies changes for all records in the dataset change log to the database.
Use ApplyUpdates to apply changes for all records in the dataset change journal to the database. This method is useful when CachedUpdates is True. The ApplyUpdates call performs the following steps:
- Fires a BeforeApplyUpdates event.
- Calls the data adapter to generate / use SQL update commands for each row and post changes to the database.
- Fires an AfterApplyUpdates event.
- Calls the Reconcile method of the dataset to reconcile any records that have errors in step 2.
- If there were no errors, then it calls CommitUpdates for the TFDCustomMemTable descendants. For the TFDRdbmsDataSet descendants (TFDQuery, TFDStoredProc, TFDTable etc) the application should call Reconcile and CommitUpdates explicitly.
AMaxErrors
indicates the maximum number of errors that FireDAC 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 change log of the dataset. If the update process is aborted before all updates are applied, any unapplied updates remain in the change log.
ApplyUpdates does not raise exceptions. Instead, the application should review erroneous records using Reconcile and the OnReconcileError event handler or FilterChanges and the RowError properties. For more details, read "Reviewing errors" at Caching Updates.
All changes are applied in the dataset modifications order. First modification (insert / update / delete) is applied first, last modification is applied last.
Example
procedure TForm1.btnApplyClick(ASender: TObject);
begin
if FDStoredProc1.UpdatesPending then
FDStoredProc1.ApplyUpdates;
end;
See Also
- Caching Updates
- FireDAC.Comp.DataSet.TFDDataSet.CachedUpdates
- FireDAC.Comp.DataSet.TFDDataSet.CancelUpdates
- FireDAC.Comp.DataSet.TFDDataSet.CommitUpdates
- FireDAC.Comp.DataSet.TFDDataSet.RowError
- FireDAC.Comp.DataSet.TFDDataSet.FilterChanges