iNo:=1;
j:=1;
iAllCount:=500000;
try
database1.StartTransaction ;
table1.DatabaseName:=database1.DatabaseName ;
table1.CachedUpdates:=True;
table1.Active :=true;
while (j<=iAllCount) do
begin
iNo:=iNo+1;
table1.Append;
table1.FieldByName('N_NO').asinteger:=iNO;
.......
j:=j+1;
end;
//table1.Post;
table1.ApplyUpdates; //写入数据库
database1.Commit ;
except
on e:Exception do
begin
database1.Rollback ;
exit;
end;
end;
table1.CommitUpdates; //写入成功后,清除数据库缓存
问:1、设置了CachedUpdates:=True;对post来说失效了吗?必须用Commit提交?
2、对于50000数据,能不能每1000条写数据库一次,只要在50次中有一次失败,数据库回滚。用事务如何实现?
3、不用table控件还有其他更好的方法?
敬请高手指点。分不够可再加。
j:=1;
iAllCount:=500000;
try
database1.StartTransaction ;
table1.DatabaseName:=database1.DatabaseName ;
table1.CachedUpdates:=True;
table1.Active :=true;
while (j<=iAllCount) do
begin
iNo:=iNo+1;
table1.Append;
table1.FieldByName('N_NO').asinteger:=iNO;
.......
j:=j+1;
end;
//table1.Post;
table1.ApplyUpdates; //写入数据库
database1.Commit ;
except
on e:Exception do
begin
database1.Rollback ;
exit;
end;
end;
table1.CommitUpdates; //写入成功后,清除数据库缓存
问:1、设置了CachedUpdates:=True;对post来说失效了吗?必须用Commit提交?
2、对于50000数据,能不能每1000条写数据库一次,只要在50次中有一次失败,数据库回滚。用事务如何实现?
3、不用table控件还有其他更好的方法?
敬请高手指点。分不够可再加。
for i:=1 to 记录总数 do
begin
try
if i mod 500=1 then
beginTrans;//启动事务
数据集.UpdateBatch(arCurrent);//提交当前缓存
if i mod 500=1 then
commitTrans;//提交事务
except
//回滚事务
end;
end;
if 事务处于启动状态 then
try
commitTrans;//提交事务
except
//回滚事务
end;