可以使用 ADO 的Batchupdate进行成批提交.
将Adoquery1.LockType 设为 ltBatchOptimistic
Adoquery1.Cursortype 设为 ctKeyset 或 ctStatic...
//对Adoquery1进行操作,可以是程序,也可以是用户通过DataAccess控件操作的
...
AdoConnection1.BeginTrans;
try
Adoquery1.UpdateBatch();
Adoconnection1.CommitTrans;
except
on E:EDatabaseError do
Adoconnection1.Rollbacktrans;
showmessage(E.message);
end;
将Adoquery1.LockType 设为 ltBatchOptimistic
Adoquery1.Cursortype 设为 ctKeyset 或 ctStatic...
//对Adoquery1进行操作,可以是程序,也可以是用户通过DataAccess控件操作的
...
AdoConnection1.BeginTrans;
try
Adoquery1.UpdateBatch();
Adoconnection1.CommitTrans;
except
on E:EDatabaseError do
Adoconnection1.Rollbacktrans;
showmessage(E.message);
end;
在adotable1.beforepost事件里面写上:
procedure TForm1.ADOTable1BeforePost(DataSet: TDataSet);
begin
adotable2.post;
end;
这样的话,似乎不太保险。如果adotable1.post完后,在处理adotable2.post的时候出现错误的话,不就倒了!虽然是在adotable1.beforepost里处理,但是总是有限后的,不太保险啊!
如果可能的话,应该考虑用触发器来实现!至于怎么用,去翻翻书吧,很简单
as
declear @field1 char(4),@field2 char(4),@field3 char(4)
select @field1=field1,@field2=field2,@field3=filed3 from inserted
if (select count(*) from table2 where table2.field3=@filed3)=0 then
rollbace transaction
else
update table2 set table2.field1=@field1,table2.field2=@field2
where table2.field3=@field3