FireDAC.Comp.DataSet.TFDDataSet.ApplyUpdates

From Appmethod Libraries
Jump to: navigation, search

Object Pascal

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:

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