例:
 adoquery1.SQL.Clear;
 adoquery1.SQL.Add('select count(*) from userlist ');
 adoquery1.Open;
如何的到adoquery1查询出来的记录总数?

解决方案 »

  1.   

    var 
      ACount:Integer;
    ...
    ACount:=adoquery1.fields[0].asInteger;
    ...或者
      adoquery1.SQL.Clear;
      adoquery1.SQL.Add( 'select   *   from   userlist   ');
      adoquery1.Open;
      ACount:=adoquery1.RecordCount;
     
      

  2.   

    你们上面两中方法我都试过拉,不好用。
    adoquery1.fields[0].value 得到的值为‘21’而实际用SQL查询得到值为‘12’。
    adoquery1.recordcount值得到的值为'21'
    郁闷啊,今天一天为这个头痛啊!
      

  3.   

    例: 
    var
      i: integer
      adoquery1.SQL.Clear; 
      adoquery1.SQL.Add( 'select   count(*) as count_  from   userlist   '); 
      adoquery1.Open; 
      
    i:=adoQuery1.fieldbyname('count_').asInteger
    如何的到adoquery1查询出来的记录总数?
      

  4.   

    直接用adoquery1.RecordCount是最简单的
      

  5.   

    楼上的
    adoquery1.RecordCount有可能出错的哦!我就遇到过的记录数为几条,但是adoquery1.RecordCount = -1;呵呵,但是我没有查到为什么会这样。
    最好就是adoQuery1.fieldbyname( 'count_ ').asInteger ,或者用一个循环来得到。
    var
      Lv_Count : Integer;
    begin
    Lv_Count := 0;
    if not adoQuery1.isEmpty then
    begin
      adoQuery1.First;
      while not adoQuery1.eof do 
      begin
        Lv_Count := Lv_Count + 1;
        adoQuery1.next;
      end;
    end;
    end;
      

  6.   

    不同意楼上的,支持 直接用adoquery1.RecordCount,没遇到过问题的!
      

  7.   

    楼上正解
    支持 直接用adoquery1.RecordCount,没遇到过问题的!
      

  8.   

    怀疑楼主数据库工作文件夹发生了变化,而设置的数据库路径还是原来的
    不然adoquery1.RecordCount是不会有问题的
      

  9.   

    RecordCount可以的,
    ADO的一些BUG会导致RecordCount等于-1,需要用最新的MDAC库
      

  10.   

    应该这样写
      用你定义的变量来获得如:
    var
    a:integer;
    begin
      adoquery1.close
      adoquery1.SQL.Clear; 
      adoquery1.SQL.Add( 'select   count(*)   from   userlist   '); 
      adoquery1.Open;
    a:=adoquery1.fields[0].asinteger;
    end; 
      

  11.   

    adoquery1.RecordCount不好用的  有时会出错 还是用adoquery1.fields[0].value
      

  12.   

    确实adoquery1.RecordCount有时候会出问题,我也遇到过!
      

  13.   

    定义变量如: 
    var 
        i:integer; 
    begin 
        adoquery1.close 
        adoquery1.SQL.Clear;   
        adoquery1.SQL.Add('select *  from   userlist ');   
        adoquery1.Open; 
        i:=adoquery1.fields[0].asinteger; 
    end;   
      

  14.   


    var 
    s:String;
    with adoquery1 do
      begin
        Close;
        SQL.clear;
        SQL.add('select count(*) as a from userlist');
        Open;
      end;
    s:=adoquery1.FieldByName('a').asstring;
    Showmessage(s);
      

  15.   

    我这里试了一个,均正常,你需要检查一下你的程序是否别的地方有问题而影响到此处.
    不过听朋友说,adoquery.recordcount是很费资源的.
      

  16.   

    你可以試著這樣看看
    adoQuery.last;
    adoQuery.frist;
    adoQuery.RecordCount
      

  17.   

    支持adoquery1.RecordCount;
    没遇到过问题
      

  18.   

    真的见鬼了 
    adoquery1.RecordCount; 
      

  19.   

    同志们 这个问题有必要讨论的这么火热吗 lz"你们上面两中方法我都试过拉,不好用。 
    adoquery1.fields[0].value   得到的值为‘21’而实际用SQL查询得到值为‘12’。 
    adoquery1.recordcount值得到的值为'21' "你程序连接的数据库 和 你是实际sql查询的数据库 是不是不同啊!!!!!
    怀疑
      

  20.   

    adoquery1.RecordCount和
    var 
    s:String;
    with adoquery1 do
      begin
        Close;
        SQL.clear;
        SQL.add('select count(*) as a from userlist');
        Open;
      end;
    s:=adoquery1.FieldByName('a').asstring;
    Showmessage(s);这个都可以,我试了都行。
      

  21.   

    'select   count(*)   from   userlist'
    用RecordCount应该不对吧,如果不是-1就是1了,count(*)只返回一条的啊,又不是用
    'select *   from   userlist'
    查询的.   手头没有环境,不能测试.