IDtBulkPacket.Data

Syntax

Data: Array;

Description

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

Example

Executing the example requires that the root of the C disk contains the Data.xls file.

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[34];
    v1[00] := "Cheese"; v1[10] := 10; v1[20] := 113.12;
    v1[01] := "Juice"; v1[11] := 20; v1[21] := 101.53;
    v1[02] := "Tea"; v1[12] := 30.45; v1[22] := 154.13;
    v1[03] := "Coffee"; v1[13] := 40; v1[23] := "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