无法再次ApplyUpdates

  • 主题发起人 主题发起人 import
  • 开始时间 开始时间
I

import

Unregistered / Unconfirmed
GUEST, unregistred user!
我来了 用ClientDataSet的时候,当ApplyUpdates成功,可由于其他表的错误导致事务回滚后,无法再次ApplyUpdates
Example:
Database1.StrartTransaction;
try
ClientDataSet1.ApplyUpdates(0); //这句成功
ClientDataSet2.ApplyUpdates(1); //这句出错
Database1.Commit;
except
Database1.Rollback;
end;
这时候ClientDataSet1的数据就无法再次ApplyUpdates了
***********************[red]解决方案[/red]*****************************
用下面这个控件吧,新加AS_ApplyUpdates和CommitUpdates
Database1.StrartTransaction;
try
ClientDataSet1.AS_ApplyUpdates(0); //这句成功
ClientDataSet2.AS_ApplyUpdates(1); //这句出错
Database1.Commit;
except
Database1.Rollback;
raise
end;
ClientDataSet1.CommitUpdates;
ClientDataSet2.CommitUpdates;
现在可以了,只要不CommitUpdates永远可以AS_ApplyUpdates
______________________________Source________________________________________
unit CClientDataSet;
interface
uses Classes, Variants, SysUtils, DB, DBClient;
type
TCClientDataSet = class(TClientDataSet)
private
FDeltaErrors: OleVariant;
public
function AS_ApplyUpdates(MaxErrors: Integer = 0): Integer;
procedure CommitUpdates;
end;
implementation
{ TCClientDataSet }
function TCClientDataSet.AS_ApplyUpdates(MaxErrors: Integer = 0): Integer;
var
OwnerData: OleVariant;
begin
CheckBrowseMode;
if ChangeCount = 0 then
begin
Result := 0;
FDeltaErrors := Null;
end
else begin
if Assigned(BeforeApplyUpdates) then BeforeApplyUpdates(Self, OwnerData);
FDeltaErrors := AppServer.AS_ApplyUpdates(ProviderName, Delta, MaxErrors, Result, OwnerData);
if Assigned(AfterApplyUpdates) then AfterApplyUpdates(Self, OwnerData);
end;
end;
procedure TCClientDataSet.CommitUpdates;
begin
if VarIsEmpty(FDeltaErrors) then Exit;
 
Reconcile(FDeltaErrors);
end;
end.
 
后退
顶部