我想在bcb中实现如下sql功能(事务处理),请问如何实现:
begin work;
insert into table1 values(a,b,c,d);
delete from table2 where a="xx";
if (sqlcode==0)
commit work;
else
rollback work;
...全文
1484打赏收藏
请教bcb中如何实现sql中的事务处理?
我想在bcb中实现如下sql功能(事务处理),请问如何实现: begin work; insert into table1 values(a,b,c,d); delete from table2 where a="xx"; if (sqlcode==0) commit work; else rollback work;
ADOConnection1.BeginTrans;
try
with ADOCommand1 do
begin
Connection:=ADOConnection1;
commandtext:='update [country] set [population]=10000 where [name]=''Venezuela''';//正确的SQL语句
Execute;
CommandText:='Wrong SQL Command';//错误的SQL
Execute;
ADOConnection1.CommitTrans;
end;
except
on E: Exception do
begin
ADOConnection1.RollbackTrans;
ShowMessage(E.Message);
end
end;
end;