IDtBulkPacket.Data

Fore syntax

Data: Array;

Fore.NET syntax

Data: System.Array;

Description

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

Fore 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 pack
    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 pack
    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 pack
    Pack.Data := v;
    Pack.StopLimit := 8;
    ExcelConsumer.PutBulk(Pack);
    If Not Pack.Successful Then
        Debug.WriteLine("Error on pack 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("Pack is exported successfully");
    End If;
    //The second pack
    Pack.Data := v1;
    Pack.StopLimit := 8;
    ExcelConsumer.PutBulk(Pack);
    If Not Pack.Successful Then
        Debug.WriteLine("Error on pack 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("Pack 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.

Fore.NET 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.

Imports Prognoz.Platform.Interop.Dt;
Imports Prognoz.Platform.Interop.Dal;
Imports Prognoz.Platform.Interop.Db;
...
Sub Main(Params: StartParams);
Var
    ExcelConsumer: IDtExcelConsumer;
    Fields: IDtFieldDefinitions;
    Field: IDtFieldDefinition;
    v, v1: Array;
    Pack: IDtBulkPacket;
    i: integer;
Begin
    //Array passed in the first pack
    v := New Object[3, 4];
    v[0, 0] := 
"Buckwheat"; v[1, 0] := 10; v[2, 0] := 313.12;
    v[0, 1] := 
"Milk"; v[1, 1] := 20; v[2, 1] := 301.53;
    v[0, 2] := 
"Sugar"; v[1, 2] := 30; v[2, 2] := 254.13;
    v[0, 3] := 
"Bread"; v[1, 3] := 40; v[2, 3] := 404.11;
    //Array passed in the second pack
    v1 := New Object[34];
    v1[00] := "Kefir"; 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.ddtString;
    Field.Name := "Name";
    Field := Fields.Add();
    Field.DataType := DbDataType.ddtInteger;
    Field.Name := "Identifier";
    Field := Fields.Add();
    Field.DataType := DbDataType.ddtFloat;
    Field.Name := "Value";
    ExcelConsumer.Open();
    Pack := New DtBulkPacket.Create();
    Pack.FailPolicy := DatasetFailPolicy.dfpRollback;
    //The first pack
    Pack.Data := v;
    Pack.StopLimit := 8;
    ExcelConsumer.PutBulk(Pack);
    If Not Pack.Successful Then
        System.Diagnostics.Debug.WriteLine("Error on pack export");
        System.Diagnostics.Debug.WriteLine("Records not exported: " + Pack.FailedRows.ToString());
        For i := v.GetLowerBound(1To v.GetUpperBound(1Do
        If Pack.Failed[i] Then
            System.Diagnostics.Debug.WriteLine(Pack.ErrorMessage[i]);
        End If;
        End For;
    Else
        System.Diagnostics.Debug.WriteLine("Pack is exported successfully");
    End If;
    //The second pack
    Pack.Data := v1;
    Pack.StopLimit := 8;
    ExcelConsumer.PutBulk(Pack);
    If Not Pack.Successful Then
        System.Diagnostics.Debug.WriteLine("Error on pack export");
        System.Diagnostics.Debug.WriteLine("Records not exported: " + Pack.FailedRows.ToString());
        For i := v1.GetLowerBound(1To v1.GetUpperBound(1Do
        If Pack.Failed[i] Then
            System.Diagnostics.Debug.WriteLine(Pack.ErrorMessage[i]);
        End If;
        End For;
    Else
        System.Diagnostics.Debug.WriteLine("Pack is exported successfully");
    End If;
    ExcelConsumer.Close();
    End Sub;

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