try
    F_dm.ADOConnection1.BeginTrans;  //启动事务
    with Adoquery1 do   //将信息保存到进货主表
    begin
      Close;
      SQl.Clear;
      SQl.Add('select * from tb_warehouse_main');
      open;
      insert;
      FieldByName('billdate').AsDateTime:=strtodate(formatdatetime('yyyy-mm-dd',datetimepicker1.Date));
      FieldByName('billcode').AsString:=Trim(Edit2.Text);
      FieldByName('units').AsString:=Trim(Edit3.Text);
      FieldByName('handle').AsString:=Trim(Edit4.Text);
       FieldByName('op').AsString:=Trim(Edit1.Text);
      FieldByName('summary').AsString:=Trim(Edit5.Text);
      FieldByName('fullpayment').AsFloat:=strtofloat(panel1.Caption);
      FieldByName('payment').AsFloat:=strtofloat(format('%10.4f',[strtofloat(Edit6.Text)]));      post;
    end;    F_dm.ADOConnection1.CommitTrans;      //提交事务
    Application.MessageBox('保存成功','提示',mb_ok);  except
    F_dm.ADOConnection1.RollbackTrans;      //回滚事务
    Application.MessageBox('保存不成功','提示',mb_ok);
  end;
这是stringrid提交保存时的代码,我现在将控件改为dbgrid,提交代码怎么改呀

解决方案 »

  1.   

    似乎是一样,上面的代码并没有用到stringgrid
      

  2.   

     For grow:=1 to strdbrows do
        begin
          with adoquery1 do
          begin
            with stringgrid1 do
            begin
              Close;
              SQL.Clear;
              SQL.Add('select * from tb_stock where tradecode='+''''+Trim(Cells[1,grow])+'''');
              Open;
              edit;
              if (fieldbyname('averageprice').AsFloat=0) then
                ave:=format('%10.4f',[(strtofloat(Cells[7,grow]) * strtofloat(Cells[8,grow]))/(strtofloat(Cells[7,grow]))])
              else
                ave:=format('%10.4f',[(strtofloat(Cells[7,grow]) * strtofloat(Cells[8,grow])+fieldbyname('averageprice').AsFloat*fieldbyname('qty').AsFloat)/(strtofloat(Cells[7,grow])+fieldbyname('qty').AsFloat)]);
              Edit;
              fieldbyname('qty').AsFloat:=fieldbyname('qty').AsFloat+strtofloat(Cells[7,grow]);
              fieldbyname('price').AsFloat:=strtofloat(format('%10.4f',[strtofloat(Cells[8,grow])]));
              fieldbyname('averageprice').AsFloat:=strtofloat(ave);
              UpdateRecord;
              post;
            end;
          end;
        end;
    这里才是
      

  3.   

    DBGRID直接用数据集的post就行.
      

  4.   

    请你好好看看一般关于Delphi数据库设计的书籍.
    把DBGrig.DataSoure.DataSet:=Adoquery1;
    在编辑的时候,请Adoquery1.Open....
    Adoquery1.Post提交
      

  5.   

    只要把dbgrid设为可编辑,关闭后会保存