I want to insert data from csv to two tables.
If there is any invalid data in the csv, the process should be rollback and made no changes to tables.
E.g. The csv file contains 4 rows and the last row has an invalid data value. When the batch run and the invalid data is found... all rows must not be inserted and the process need to stop.
This is my code...
---
private void insertCustomTable(container _container)
{
CustomTable z_CustomTable;
NewTable z_NewTable;
ttsBegin;
try
{
// CustomTable
z_CustomTable.Name = conPeek(_container, 1);
z_CustomTable.Address = conPeek(_container, 2);
z_CustomTable.insert();
// NewTable
z_NewTable.clear();
z_NewTable.initValue();
z_NewTable.initFromCustomTable(z_CustomTable);
z_NewTable.Description = conPeek(_container, 3);
z_NewTable.ID = conPeek(_container, 4);
z_NewTable.insert();
ttsCommit;
}
catch(Exception::CLRError)
{
ttsAbort;
info(CLRInterop::getLastException().toString());
}
---
The problem is the process only stop at the error row and the correct rows get inserted into tables.
If 4th row has error, the 1,2,3rd rows are inserted.
If 1st row has error, the 2,3,4th rows are not inserted.
The process stopped only if it detects the error and the previous correct rows are inserted into tables.
Please Advice.