IDtBulkPacket.Data

Syntax

Data: Array;

Description

The Data property determines two-dimensional array of data to be exported within one transaction.

Example

Executing the example requires the Data.xls file in the disk C root directory.

Add links to the Dt, Dal, Db system assemblies to execute the example.

Sub Main;
Var
    ExcelConsumer: IDtExcelConsumer;
    Fields: IDtFieldDefinitions;
    Field: IDtFieldDefinition;
    v, v1: Array;
    Pack: IDtBulkPacket;
    i: integer;
Begin
    //Array passed in the first packet
    v := New Variant[34];
    v[00] := "Buckwheat"; v[10] := 10; v[20] := 313.12;
    v[01] := "Milk"; v[11] := 20; v[21] := 301.53;
    v[02] := "Sugar"; v[12] := 30; v[22] := 254.13;
    v[03] := "Bread"; v[13] := 40; v[23] := 404.11;
    //Array passed in the second packet
    v1 := 
New Variant[3, 4];
    v1[0, 0] := 
"Kefir"; v1[1, 0] := 10; v1[2, 0] := 113.12;
    v1[0, 1] := 
"Juice"; v1[1, 1] := 20; v1[2, 1] := 101.53;
    v1[0, 2] := 
"Tea"; v1[1, 2] := 30.45; v1[2, 2] := 154.13;
    v1[0, 3] := 
"Coffee"; v1[1, 3] := 40; v1[2, 3] := "A";
    ExcelConsumer := New DtExcelConsumer.Create;
    ExcelConsumer.File := "d:\Data.xls";
    ExcelConsumer.HasHeader := True;
    ExcelConsumer.DriverVersion := "Excel 8.0";
    ExcelConsumer.Table := "Sheet1";
    Fields := ExcelConsumer.Fields;
    Field := Fields.Add;
    Field.DataType := DbDataType.String;
    Field.Name := "Name";
    Field := Fields.Add;
    Field.DataType := DbDataType.Integer;
    Field.Name := "Identifier";
    Field := Fields.Add;
    Field.DataType := DbDataType.Float;
    Field.Name := "Value";
    ExcelConsumer.Open;
    Pack := New DtBulkPacket.Create;
    Pack.FailPolicy := DatasetFailPolicy.Rollback;
    //The first packet
    Pack.Data := v;
    Pack.StopLimit := 8;
    ExcelConsumer.PutBulk(Pack);
    If Not Pack.Successful Then
        Debug.WriteLine("Error on packet export");
        Debug.WriteLine("Records not exported: " + Pack.FailedRows.ToString);
          For i := v.GetLowerBound(1To v.GetUpperBound(1Do
        If Pack.Failed(i) Then
            Debug.WriteLine(Pack.ErrorMessage(i));
        End If;
        End For;
    Else
        Debug.WriteLine("Packet is exported successfully");
    End If;
    //The second packet
    Pack.Data := v1;
    Pack.StopLimit := 8;
    ExcelConsumer.PutBulk(Pack);
    If Not Pack.Successful Then
        Debug.WriteLine("Error on packet export");
        Debug.WriteLine("Records not exported: " + Pack.FailedRows.ToString);
          For i := v1.GetLowerBound(1To v1.GetUpperBound(1Do
        If Pack.Failed(i) Then
            Debug.WriteLine(Pack.ErrorMessage(i));
        End If;
        End For;
    Else
        Debug.WriteLine("Packet is exported successfully");
    End If;
    ExcelConsumer.Close;
End Sub Main;

After executing the example a new data consumer, that exports data in Excel file, is created. Values of two arrays are in turns written in file. Information about export results is displayed in the development environment console. If there are any records that are not exported by any reason, the error message is displayed in the console window.

See also:

IDtBulkPacket