将TAdoTable 或TAdoQuery改为CacheUpdates设置为true,再用事务提交的办法。
在AfterInsert, AfterDelet或者AfterPost事件中执行如下代码:
with CustomerQuery do
begin
Database1.StartTransaction;
try
ApplyUpdates; {try to write the updates to the database};
Database1.Commit; {on success, commit the changes};
except
Database1.Rollback; {on failure, undo the changes};
raise; {raise the exception to prevent a call to CommitUpdates!}
end;
CommitUpdates; {on success, clear the cache}
end;