With AdoQ Do
    Begin
      Close;
      Sql.Clear;
      Sql.Add('Select * From Abc');
      Open;
    End;
  If Not Adoq.IsEmpty Then
    Begin
      I:=1;
      While Not Adoq.Eof Do
        Begin
          StringGrid1.Cells[0,I]:=IntToStr(I);
          StringGrid1.Cells[1,I]:=AdoQ['Lx'];
          StringGrid1.Cells[2,I]:=AdoQ['Bs'];
          StringGrid1.Cells[3,I]:=AdoQ['Dwmc'];
          Adoq.Next;
        End;
    End;
  AdoQ.Close;
  Adoq.Sql.Clear;这是一段嵌在DLL中的代码,为什么运行到AdoQ.Close就报错?
错误如下:Bof或Eof中有一个有"真",或当前的记录已被删除,所需的操作需要一个当前记录.
运行情况是这样的,表中有二条记录,但StringGrid1中只显示了一条,循环已经运行完了,为什么只显示一条呢?DELPHI5.0 Ado的补丁我已经打了呀!!!!各位大虾救命啊

解决方案 »

  1.   

    With AdoQ Do
        Begin
          Close;
          Sql.Clear;
          Sql.Add('Select * From Abc');
          Open;
        End;
      if Adoq.recordcount <= 0 then
      begin
        Adoq.close;
        exit;
      end;
      
      for i := 0 to Adoq.recordcount - 1 do
      begin
        StringGrid1.Cells[0,I+1] = IntToStr(I+1);
        StringGrid1.Cells[1,I+1]:=AdoQ['Lx'];
        StringGrid1.Cells[2,I+1]:=AdoQ['Bs'];
        StringGrid1.Cells[3,I+1]:=AdoQ['Dwmc'];
        Adoq.Next;
      end;
      Adoq.close;try it
      

  2.   

    If Not Adoq.IsEmpty Then
    改为
    if (Not ADOQ.IsEmpty) and (Not ADOQ.Eof) then
    试试
      

  3.   

    不可能是ADOQ.Close这句话出的错,而是因为这句的上一句的错误!因为到达末尾的时候你又调用了一次ADOQ.Next,所以会出错的!所以我觉得我的建议是正确的!
      

  4.   

    你的I没有增加过
    While Not Adoq.Eof Do
            Begin
              StringGrid1.Cells[0,I]:=IntToStr(I);
              StringGrid1.Cells[1,I]:=AdoQ['Lx'];
              StringGrid1.Cells[2,I]:=AdoQ['Bs'];
              StringGrid1.Cells[3,I]:=AdoQ['Dwmc'];
              Adoq.Next;
              inc(i);  //加上就好了
            End;
      

  5.   

    1、關閉之前先判斷一下ado的state屬性,如果等於0証明記recordset已關閉,則不可再次關閉2、檢查一下status屬性,看當前記錄處於什麼狀態下,返回值代表的含議可在ado幫助裡查到。try it.
      

  6.   

    isempty是判断query有没有记录呀!与eof有别!
      

  7.   

    With AdoQ Do
    Begin
         Close;
         Sql.Clear;
         Sql.Add('Select * From Abc');
         Open;  if Adoq.recordcount <= 0 then
      begin
        Adoq.close;
        exit;
      end;
      
      for i := 0 to Adoq.recordcount - 1 do
      begin
        StringGrid1.Cells[0,I+1] = IntToStr(I+1);
        StringGrid1.Cells[1,I+1]:=AdoQ['Lx'];
        StringGrid1.Cells[2,I+1]:=AdoQ['Bs'];
        StringGrid1.Cells[3,I+1]:=AdoQ['Dwmc'];
        Adoq.Next;
      end;end;
      Adoq.close;
      

  8.   

    With AdoQ Do
        Begin
          Close;
          Sql.Clear;
          Sql.Add('Select * From ABC');
          Open;
        End;
      If (Not Adoq.IsEmpty) And (Not AdoQ.Eof) Then
        Begin
          I:=1;
     //     While Not Adoq.Eof Do
          For I:=0 To AdoQ.recordcount-1 Do
            Begin
              StringGrid1.Cells[0,I+1]:=IntToStr(I);
              StringGrid1.Cells[1,I+1]:=AdoQ['Lx'];
              StringGrid1.Cells[2,I+1]:=AdoQ['Bs'];
              StringGrid1.Cells[3,I+1]:=AdoQ['Dwmc'];
    //          I:=I+1;
              Adoq.Next;
            End;
        End;
      AdoQ.Close;
      Adoq.Sql.Clear;
    这些都不行啊!问题到底在哪?
      

  9.   

    1 先用isempty或者fields[0].isnull判断一下是否表为空
    2 在close前添加first试试
      

  10.   

    First果然有效,谢谢风焱.但我想知道,为什么要First呢?没理由啊???
      

  11.   

    我已经查到问题了,问题出在delphi5.0的ado更新上:(
    但我只有第二个ADO的更新包,谁有第一个?
      

  12.   

    With AdoQ Do
        Begin
          Close;
          Sql.Clear;
          Sql.Add('Select * From Abc');
          Open;
        End;
      If Not Adoq.eof Then
        Begin
          I:=1;
          While Not Adoq.Eof Do
            Begin
              StringGrid1.Cells[0,I]:=IntToStr(I);
              if (AdoQ['Lx']<>NULL) and (AdoQ['Lx']<>'') then
              StringGrid1.Cells[1,I]:=AdoQ['Lx'];
              if (AdoQ['Bs']<>NULL) and (AdoQ['Bs']<>'') then
              StringGrid1.Cells[2,I]:=AdoQ['Bs'];
              if (AdoQ['Dwmc']<>NULL) and (AdoQ['Dwmc']<>'') then
              StringGrid1.Cells[3,I]:=AdoQ['Dwmc'];
              Adoq.Next;
            End;
        End;
      AdoQ.Close;
      Adoq.Sql.Clear;
      

  13.   

    他有用的原因是-------
    borland的bug:)