没有使用 update 语句,直接在 while 中修改数据是否可行?
   while not Eof do
     begin       //............处理其它事       Edit;
       FieldByName('xxx').AsString:='1';
       Post;       Next;
     end;

解决方案 »

  1.   

    如果要写入到数据库中,还需要调用ApplyUpdates函数(如果你使用dbexpress连数据库的话),如果是用ado连接的,则调用UpdateBatch
      

  2.   

    直接用Update sql 不就可以了吗?为什么非要这么做呢?
      

  3.   

    如果ADO是直接连接,是可行的。如果是间接连接(C/S)行不通。 
      

  4.   

    可行:(while 和 for to do類似吧)procedure TCQ_JB_F.N1Click(Sender: TObject);
    var
      iLoop:integer;
    begin
      inherited;
      CQ_JB_P_F:=TCQ_JB_P_F.Create(Self);
      if CQ_JB_P_F.ShowModal=mrok then
      begin
        cxGrid2.BeginUpdate;
        cxGrid2DBBandedTableView1.BeginUpdate;
        for iLoop:=0 to cxGrid2DBBandedTableView1.DataController.GetSelectedCount -1 do
        begin
          cxGrid2DBBandedTableView1.Controller.FocusedRow:=cxGrid2DBBandedTableView1.Controller.SelectedRows[iLoop];
          adoq_JB.Edit;
          adoq_JB.FieldByName('JBRQ').AsString:=FormatDateTime('yyyy/mm/dd',DT);
          adoq_JB.FieldByName('KSSJ').AsString:=FormatDateTime('hh:mm:ss',DtKSSJ);
          adoq_JB.FieldByName('JSSJ').AsString:=FormatDateTime('hh:mm:ss',DtJSSJ);
          adoq_JB.FieldByName('JBYY').AsString:=StrJBYY;
          adoq_JB.FieldByName('JBDD').AsString:=StrID;
          adoq_JB.FieldByName('STATUS').AsString:=StrJBLX;
        end;
        cxGrid2DBBandedTableView1.EndUpdate;
        cxGrid2.EndUpdate;
      end;  
    end;
      

  5.   

    再更正一下,效率會更高:
    procedure TRES_CQ_JB_F.N1Click(Sender: TObject);
    var
      iLoop:Integer;
    begin
      inherited;
      if _JuMaPao=3 then
      begin
        if IsZCJB=2 then
        begin
          CQ_JB_P_F:=TCQ_JB_P_F.Create(Self);
          if CQ_JB_P_F.ShowModal=mrok then
          begin
            cxGrid2.BeginUpdate;
            cxGrid2DBTableView1.BeginUpdate;
            for iLoop:=0 to cxGrid2DBTableView1.DataController.GetSelectedCount -1 do
            begin
              cxGrid2DBTableView1.Controller.FocusedRow:=cxGrid2DBTableView1.Controller.SelectedRows[iLoop];
              adoq_JB.Edit;
              adoq_JB.FieldByName('JBRQ').AsString:=FormatDateTime('yyyy/mm/dd',DT);
              adoq_JB.FieldByName('SJKSSJ').AsString:=FormatDateTime('hh:mm:ss',DtKSSJ);
              adoq_JB.FieldByName('SJJSSJ').AsString:=FormatDateTime('hh:mm:ss',DtJSSJ);
              adoq_JB.FieldByName('SJJBSS').AsString:=FormatDateTime('hh:mm:ss',FlGZSS);
              adoq_JB.FieldByName('JBYY').AsString:=StrJBYY;
              adoq_JB.FieldByName('JBDD').AsString:=StrID;
              adoq_JB.FieldByName('STATUS').AsString:=StrJBLX;
              adoq_JB.Post;
            end;
            cxGrid2DBTableView1.EndUpdate;
            cxGrid2.EndUpdate;
          end;
        end;
      end;
    end;
      

  6.   

    几乎从不用TABLE之类的控件,感觉不爽,喜欢直接用SQL,实际上你放个控件在哪里插入数据,有必要吗,