使用DataSetProvider的ApplyUpdate增加或者修改資料的樣例
阿新 • • 發佈:2019-01-29
function TRDMEnterCaseServer.UpdateBugInfo(BugDelta: OleVariant;
var aMsg: OleVariant): OleVariant;
var
ErrorCount: Integer;
BUGID: Integer;
begin
ErrorCount := 0; // 用於在更新過程中記錄發生錯誤的次數
Result := False; // 返回本次操作是否成功
aMsg := ''; // 若發生錯誤返回錯誤資訊
try
if not VarIsEmpty(BugDelta) then
begin
ClientDs.Data := BugDelta;
ClientDs.First();
BUGID := 1;
while not ClientDs.Eof do
begin
case ClientDs.UpdateStatus of
usInserted:
begin
while IDIsExist(adoQryTemp, 'BL_TBL_BUG', 'BUGID', IntToStr(BUGID)) do// 確保BUGID的編號唯一
BUGID := BUGID + 1;
ClientDs.Edit();
ClientDs.FieldByName('BUGID').AsInteger := BUGID;
ClientDs.Post;
BUGID := BUGID + 1;
end;
usUnmodified:
begin
ClientDs.Next();
end;
end;
ClientDs.Next();
end;
dsProvider.DataSet := adoQry;
adoQry.Close;
adoQry.Connection := DMCaseServer.adoCon1;
adoQry.SQL.Clear;
// 若要實現無狀態,這一步是必須的,因為要根據以上語句生成更新語句
adoQry.SQL.Add('Select * from BL_V_BUG where BUGID = -1');
adoQry.Open;
dsProvider.ApplyUpdates(ClientDs.Data, -1, ErrorCount);
end;
var aMsg: OleVariant): OleVariant;
var
ErrorCount: Integer;
BUGID: Integer;
begin
ErrorCount := 0; // 用於在更新過程中記錄發生錯誤的次數
Result := False; // 返回本次操作是否成功
aMsg := ''; // 若發生錯誤返回錯誤資訊
try
if not VarIsEmpty(BugDelta) then
begin
ClientDs.Data := BugDelta;
ClientDs.First();
BUGID := 1;
while not ClientDs.Eof do
begin
case ClientDs.UpdateStatus of
usInserted:
begin
while IDIsExist(adoQryTemp, 'BL_TBL_BUG', 'BUGID', IntToStr(BUGID)) do// 確保BUGID的編號唯一
BUGID := BUGID + 1;
ClientDs.Edit();
ClientDs.FieldByName('BUGID').AsInteger := BUGID;
ClientDs.Post;
BUGID := BUGID + 1;
end;
usUnmodified:
begin
ClientDs.Next();
end;
end;
ClientDs.Next();
end;
dsProvider.DataSet := adoQry;
adoQry.Close;
adoQry.Connection := DMCaseServer.adoCon1;
adoQry.SQL.Clear;
// 若要實現無狀態,這一步是必須的,因為要根據以上語句生成更新語句
adoQry.SQL.Add('Select * from BL_V_BUG where BUGID = -1');
adoQry.Open;
dsProvider.ApplyUpdates(ClientDs.Data, -1, ErrorCount);
end;