IDtBulkPacket.FailPolicy

Syntax

FailPolicy: DatasetFailPolicy;

Description

The FailPolicy property determines action type, that is implemented if an error occurs during data export.

Example

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

Sub Main;

Var

ExcelConsumer: IDtExcelConsumer;

Fields: IDtFieldDefinitions;

Field: IDtFieldDefinition;

v, v1: Array;

Pack: IDtBulkPacket;

Begin

//Array passed in the first packet

//Array passed in the second packet

ExcelConsumer := New DtExcelConsumer.Create;

ExcelConsumer.File := "c:\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;

//First packet

Pack.Data := v;

ExcelConsumer.PutBulk(Pack);

If Not Pack.Successful Then

Debug.WriteLine("Error during packet export");

Debug.WriteLine("Entries are not exported: " + Pack.FailedRows.ToString);

Else

Debug.WriteLine("Packet export is successfully completed");

End If;

//Second packet

Pack.Data := v1;

ExcelConsumer.PutBulk(Pack);

If Not Pack.Successful Then

Debug.WriteLine("Error during packet export");

Debug.WriteLine("Entries are not exported: " + Pack.FailedRows.ToString);

Else

Debug.WriteLine("Packet export is successfully completed");

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. If any error appears during rows export changes are undone. Information about export results is displayed in the development environment console.

See also:

IDtBulkPacket