有两种方法吧
从数据表中合计
给一个临时ADOQuery组件 执行这条SQL语句
StrSQL := 'select Sum(FieldB) iTemp from TableName';
Edit1.Text := ADOQuery1.FieldByName('iTemp').AsString;
第二种可以直接从DBGrid中合计

解决方案 »

  1.   

    procedure GetSum:integer;
    var
      Book:TBookMark;
      Atotal:Integer;
    begin
      Atotal:=0;
      With dbgrid.DataSource.DateSet do
      begin
        BookMark:=GetBookMark;
        try 
          DisableControls;
          first;
          While Not Eof do
          begin
            INc(Atotal,FieldbyName('b').asInteger);
            Next;
          end;
          Enablecontrols;
        finally
          GotoBookMark(book);
          BookMark.free;                 
        end;  
        Result:=Atotal; 
      end;   
    end;
      

  2.   

    用查询 'select sum(b) from tablename'
    注意dbgrid 中的数据是否和数据库中的一致,因为数据可能发生变化,而没有保存到数据库中
      

  3.   

    Table1.first;
    while not Table1.eof do
    begin
      Edit1.text:=floattostr(strtofloat(Edit1.text)+strtofloat(b.asstring));
    Table1.next;
    end;
      

  4.   

    我是在dbgrid中统计,不是在表中,如果在表里统计就会出错,因为dbgrid中的数据我已经是过滤出来的  
      

  5.   

    with dbgrid1.DataSource.DataSet do
    begin
    for i:=0 to recordcount -1 do
     begin 
          edit.text:=floattostr(strtofloat(edit.text)+FieldByName ('b').Value);
      next;
    end;
    end;
      

  6.   

    按qinbao01() 所说的做还是不行啊,怎么也得不出正确的结果
      

  7.   

    if adoquery1.recordcount>0 then
    begin
       adoquery1.first;
       while not adoquery1.eof do
       begin 
         edit.text:=floattostr(strtofloat(edit.text) +adoquery1.FieldByName('b').Value);
         next;
       end;
    end;
    注:adoquery1是你的那个dbgrid1中的datasource的dataset,所连的query.