with adoquery1 do
begin
close;
sql.clear;
sql.add('select * from scyb wheresid='12121');
open;
end;
if adoquery1.recordcount=0 then
begin
end;
此条语句如果scyb中有数据的话此则成功,如果scyb是个空表的话recordcount就总返回1,用select count(*) 语句,取count的返回值也不行,总是得1,不知道为什么?

解决方案 »

  1.   

    if adoquery1.recordcount=0 then
    改为
    if not (adoquery1.eof and adoquery1.bof) then
      

  2.   

    sql.add('select * from scyb wheresid='+'12121');
    if adoquery1.recordcount>0 then 代表不为空
      

  3.   

    adoquery1.last ;
    adoquery1.first ;
    if adoquery1.recordcount=0 then
    begin
    end;或者if adoquery1.IsEmpty then
    begin
    end ;
      

  4.   

    select count(*) 语句,取count的返回值也不行,总是得1,不知道为什么?如果是用这种方法的话,要这样:
    if adoquery1.Fields.Fields[0].AsInteger > 0 then
    begin
    end ;
      

  5.   

    但如果在sql的查询分析器中得到的返回结果就是0,而不是delphi中返回的值0。
      

  6.   

    select Count(*) as k from table   
     ShowMessage(FieldByName('k').AsString)  ; // 新建一个表看看是不是 0
      

  7.   

    我遇过此类问题,不过那时还是用D4, 数据库用的是Paradox.
      

  8.   

    我也遇到过这种问题query的recordcount有时候是不准,当指针在第一条纪录时它是准确的。
    所以要想判断是否为空应该用:IsEmpty
    if query1.IsEmpty then   //如果为空
       begin
       //你要做的事情
       end;
      

  9.   

    我想如果按 yutaocool(酷鱼) 所说的——query的recordcount有时候是不准,当指针在第一条纪录时它是准确的
    那就加个:adoQuery1.first;