IDatasetBatchUpdate.Commit

Syntax

Commit: Boolean;

Description

The Commit method applies update (saves values of clipboard records into the data source).

Comments

On record updating, existing record is searched in a data source by values of key fields. Required values are taken from clipboard. If record was not found, new record is added into a data source.

Example

Executing the example requires that the repository contains a table with the Table_1 identifier. The table contains three fields with integer values.

Add links to the Metabase, Db system assemblies.

Sub UserProc;
Var
    MB: IMetabase;
    Dsi: IDatasetInstance;
    Fields: IDatasetInstanceFields;
    Dbu: IDatasetBatchUpdate;
    Vals: Array[0..2Of Variant;
    i: Integer;
Begin
    MB := MetabaseClass.Active;
    Dsi := MB.ItemById("SOURSE").Open(NullAs IDatasetInstance;
    Fields := Dsi.Fields;
    Dbu := Dsi.CreateBatchUpdate;
    Dbu.BatchCommand := DatasetBatchCommand.Update;
    Dbu.KeyFieldNames := Fields.Item(0).Id;
    Dbu.FailPolicy := DatasetFailPolicy.CommitByRow;
    Dbu.BeginUpdate;
    While Not Dsi.Eof Do
        i := Fields.Item(0).Value As Integer;
        If i > 100 Then
            Vals[0] := i;
            Vals[1] := Fields.Item(1).Value;
            Vals[2] := (i - (Fields.Item(1).Value As Integer)) * 100;
            Dbu.AddRecord(Vals);
        End If;
        Dsi.Next;
    End While;
    Dbu.Commit;
End Sub UserProc;

After executing the example, records, which values of the first field are more than 100, are updated in the table. On updating, value of the third field is changed taking into account values of previous two fields.

See also:

IDatasetBatchUpdate