使用DataSetProvider的ApplyUpdate增加或者修改数据的样例

 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;

    if ErrorCount <> 0 then
    begin
      aMsg := FErrorMsg;
      exit;
    end;
    Result := True;
  except
    on E: Exception do
    begin
      aMsg := E.Message;
    end;
  end;         
end;

 

// 判断某个表中的某个字段中是否存在此值

function IDIsExist(ado: TADOQuery; TableName, FieldName, FieldValue: string): Boolean;
begin
  Result := False;
  with ado do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from ' + TableName + ' where '+ FieldName + ' = ' + FieldValue);
    Open;
    if RecordCount > 0 then
      Result := True;
  end;
end;

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值