adoqry := TADOQuery.Create(nil);
  try
    adoqry.Connection := ADOConnection1;
    adoqry.Close;
    adoqry.SQL.Clear;
    adoqry.SQL.Add('select a,b from table');
    adoqry.Open;
    while not adoqry.Eof do
    begin
      if adoqry.FieldByName('a').AsString = 'message1' then
      begin
        btxt.Text :=adoqry.FieldByName('b').AsString;
      end
    end;
    adoqry.Close;
  end为什么  adoqry.Close 到这个地方就出错。说什么 eof,bof。我这个table是个空表。
用的是ado。

解决方案 »

  1.   

      adoqry := TADOQuery.Create(nil); 
      try 
        adoqry.Connection := ADOConnection1; 
        adoqry.Close; 
        adoqry.SQL.Clear; 
        adoqry.SQL.Add('select a,b from table'); 
        adoqry.Open; 
        while not adoqry.Eof do 
        begin 
          if adoqry.FieldByName('a').AsString = 'message1' then 
          begin 
            btxt.Text :=adoqry.FieldByName('b').AsString; 
          end 
          adoqry.next;
        end; 
        adoqry.Close;
      finally
         adoqry.free;   
      end 
      

  2.   

    谢谢,不过按照你 写的,执行到 adoqry.Close还是出来那个错误。
      

  3.   

    本地测试N次,table表里就算没有数据,下面代码也没有问题--表结构,测试数据create table [table](a varchar(10) not null,b varchar(10) not null)
    insert into [table] 
    select 'message1','kaikai' union all
    select 'kkkk','BBBB'D代码:procedure TForm1.Button1Click(Sender: TObject);
    var
    adoqry:Tadoquery;
    begin
    adoqry := TADOQuery.Create(nil);
     with adoqry do
     begin
      try
        Connection:=ADOConnection1;
        Close;
        SQL.Text:='select a,b from [table]'; {如果你的表名是table,那么要加上中括号,不然open时会出错}
        Open;
        while not Eof do
         begin
          if FieldByName('a').AsString = 'message1' then
            btxt.Text :=FieldByName('b').AsString;  {btxt.Text='kaikai'}
          Next; {须有next,不然会死循环}
         end;
        Close;
      finally  
        Free; {释放}
      end;
     end;
    end;
      

  4.   

      adoqry := TADOQuery.Create(nil);
      adoqry.Connection := ADOConnection1;
      try
        with adoqry do
        begin
          close;
          sql.text := 'select a,b from table';
          Open;
          while not eof do
          begin
            if adoqry.FieldByName('a').AsString = 'message1' then
            begin
              btxt.Text :=adoqry.FieldByName('b').AsString;
            end
            Next;
          end;
        end;
      finally
        adoqry.free;
      end;
      

  5.   

    谢谢各位了。我知道原因了。
    我用的是delphi5,ado没有更新的缘故。
    更新了以后就好了。