Hello
I need to update a record in the Employee table, and, if that is succesful, create another record in the same table. This follows the lines of the classic bank transaction where one account is debited & the other credited, so I would like to have the ablity to Rollback the transaction if either transaction is unsuccesful.
I dynamically create a TTransactionDesc and a TSQLDataset then process the first update...
TD.IsolationLevel := xilREADCOMMITTED; // default
TD.TransactionID := 1;
aSQLDSet := TSQLDataset.Create(nil);
try
aSQLDSet.SQLConnection := SQLConnection1;
aSQLDSet.SQLConnection.StartTransaction(TD);
aSQLDSet.CommandText := SQLUPDADDR;
aSQLDSet.ParamByName('EMPLOYEEID').AsInteger := iType;
try
aSQLDSet.ExecSQL;
***??
aSQLDSet.SQLConnection.Commit(TD);
except
on E:Exception do
begin
//msgbox about failure
aQLDSet.SQLConnection.RollBack(TD);
end;
end;
...which works great, but I need to repeat the process to INSERT the new row that I need. Can I just put in another CommandText and new params in the line ***??, or is there a better way to do this.
Thanks & TIA
I need to update a record in the Employee table, and, if that is succesful, create another record in the same table. This follows the lines of the classic bank transaction where one account is debited & the other credited, so I would like to have the ablity to Rollback the transaction if either transaction is unsuccesful.
I dynamically create a TTransactionDesc and a TSQLDataset then process the first update...
TD.IsolationLevel := xilREADCOMMITTED; // default
TD.TransactionID := 1;
aSQLDSet := TSQLDataset.Create(nil);
try
aSQLDSet.SQLConnection := SQLConnection1;
aSQLDSet.SQLConnection.StartTransaction(TD);
aSQLDSet.CommandText := SQLUPDADDR;
aSQLDSet.ParamByName('EMPLOYEEID').AsInteger := iType;
try
aSQLDSet.ExecSQL;
***??
aSQLDSet.SQLConnection.Commit(TD);
except
on E:Exception do
begin
//msgbox about failure
aQLDSet.SQLConnection.RollBack(TD);
end;
end;
...which works great, but I need to repeat the process to INSERT the new row that I need. Can I just put in another CommandText and new params in the line ***??, or is there a better way to do this.
Thanks & TIA