if (i<=dm.adoquery2.RecordCount) and (j<=dm.adoquery3.RecordCount)then
 begin  With dm.adoquery1 DO
  begin
     Close;
     SQL.Clear;
     sql.Add('select zbry from x_xmrz where rq=:a and xmmc=:b and cz=:c');
     Parameters.ParamByName('a').Value:=FormatDateTime('yyyy-mm-dd',dtp.Date);
     Parameters.ParamByName('b').Value:=StringGrid1.Cells[0,j];
     Parameters.ParamByName('c').Value:=StringGrid1.Cells[i,0];
     Open;
  end;    if  not  dm.adoquery1.EOF  then
    begin
    StringGrid1.Cells[i,j]:=dm.ADOQuery1.fieldbyname('zbry').asstring;
    end
    else
    begin
    StringGrid1.Cells[i,j]:='无';
    end;  i:=i+1;
  j:=j+1;
    end;

解决方案 »

  1.   

      
      if (i<=dm.adoquery2.RecordCount) and (j<=dm.adoquery3.RecordCount)then
     begin  With dm.adoquery1 DO
      begin
      Close;
      SQL.Clear;
      sql.Add('select zbry from x_xmrz where rq=:a and xmmc=:b and cz=:c');
      Parameters.ParamByName('a').Value:=FormatDateTime('yyyy-mm-dd',dtp.Date);
      Parameters.ParamByName('b').Value:=StringGrid1.Cells[0,j];
      Parameters.ParamByName('c').Value:=StringGrid1.Cells[i,0];
      Open;
      end;  if not dm.adoquery1.EOF then
      begin
      StringGrid1.Cells[i,j]:=dm.ADOQuery1.fieldbyname('zbry').asstring;
      end
      else
      begin
      StringGrid1.Cells[i,j]:='无';
      end;
      
      dm.adoquery1.next;           //加这句  i:=i+1;
      j:=j+1;
      end;
      
      

  2.   

    dm.adoquery1.next;           //加这句
    加的位置已经给出,如上面的代码。
      

  3.   

    除了dm.adoquery1.next外
    最好再加上这句 dm.adoquery1.first;  
    在 if not dm.adoquery1.EOF then 上边
             
      

  4.   

    楼上的两位为什么都认为要给ADOQuery1执行Next呢?
      

  5.   

    循環時從第一筆到最後一筆,一般會加first和next...
    但不知道為什麼這樣寫,多次與database交互讀取,效率低
      

  6.   

    不需要.next
    但上面的代码似乎没有作循环
    再有,yyyy-mm-dd好像错了,应该是:yyyy-MM-dd
    mm好像是分钟的意思还有,你也没有说出错什么了
      

  7.   

    我倒,还真的是没循环,楼主啊。
    你咋会写  if not dm.adoquery1.EOF then呢,你是不是想写
    while not dm.adoquery1.EOF do啊? 
      

  8.   

    使用not eof判断查询的结果当中有没有记录,这有什么问题?
      

  9.   

    虽然说这种用法不是太准确,但是绝大部分时候相当大部分人都是这样子做的。但是并不是说判断了not eof就一定是循环。
      

  10.   

    在FormatDateTime函数当中,mm如果前面接的是时间,比如h之类的,那就表示分钟,否则表示月份,如果想要单独表示分钟,应该使用的是n而不是m。