adofind.Clone(adoquery2);
    adofind.First;
    while not  adofind.eof do
    begin
      ......
      adofind.Next ;
    end;这是我的代码,在D2010下运行,问题在
    adofind.First;
    while not  adofind.eof do
程序读到 while not  adofind.eof do 后又跳转到 adofind.First; 并不去执行循环体里的内容。就是一直那死循环状。
但相同的代码我在D6下又执行成功。不知道是什么原因了。另外还有一个问题,adoquery 和dbgrid
adoquery是缓存模式。
里面的数据大概是这样:
字段1,字段2,字段3
1001,A,12
1001,B, 32
1002, A, 10
1001, C, 10
在还没有执行POST之前
我该怎么操作去获得
1001共有54, 1002共有10

解决方案 »

  1.   

    第一个: 如果D6没问题的话,你可以加个计数. 
    i:= 1;
    while i<> recordcount do
    begin
    ...
    next;
    i:= i+1;
    end;第二个: 可以循环加
    sum:= 0;
    for i:= 0 to recordcount -1 do
    begin
    if fields[0].asstring = '1001' then sum:= sum+ fields[2].asinteger;
    next;
    end;
      

  2.   

    1.while不用first試試;
      while not adofind.eof do
      begin
      ......
      adofind.Next ;
    2.可以定義一個integer變量a,給它賦初始值為0,試試
      

  3.   


    已经测过,不行。当adofind.First就出现假死状态 
      

  4.   


    第一个问题,如果不用first,那么循环体就执行一次
    第二个问题,如果按这样做,没办法分类,或许我没有理解到你的意思,麻烦你能在说详细些吗
      

  5.   

    不知道这位兄台能不能在详细些,在未提交之前是不能SELECT 的
      

  6.   


    你改成for ... to ... do的形式測試過沒
    如:
       cx_zxb.Properties.Items.Clear;
      cx_zxb.Text:='';
          swhere:=' and CB in ('''+ cx_hbcb.Text+''')';
          qry_BaseTemp.Close;
          qry_BaseTemp.SQL.Text:='select distinct XB from Res_User_Temp where XB is not NULL and XB <>'''' and KB='''+ cx_bmkb.Text+''' and (jn<>''離職'')'+ swhere;
          qry_BaseTemp.Open;
          qry_BaseTemp.First;
          for i:=0 to qry_BaseTemp.RecordCount -1 do
          begin
            cx_zxb.Properties.Items.Add(Trim(qry_BaseTemp.FieldValues['XB']));
            qry_BaseTemp.Next;
          end;
        end;
      

  7.   


    兄台,用了你说的方法可以了。但是我还是不明白一点 first 搭配 while 就会出问题吗?