还有如下问题?
adoquery1.sql.clear;
adoquery1.sql.Text:='select count(*) from numcount where hgnum=trim(edit1.text)';
adoquery1.open;
Label2.Caption:=adoquery1.;
为了得到count(*)值,省略号处应该怎么写?当adoquery1.sql.Text:='select * from numcount where hgnum=trim(edit1.text)';语句没有符合条件的记录时,会不会有返回值?怎样得到这个返回值 ?

解决方案 »

  1.   

    为了得到count(*)值,省略号处应该怎么写?inttostr(adoquery1.RecordCount);
      

  2.   

    无返回值,
    但可判断adoquery1.RecordCount这个值,
    如果为0
    即为没有满足条件的记录
      

  3.   

    1。adoquery1.fields.fields[0].asstring,不过最好建议你给count(*) 取个别名!
    2。没有记录的时候会得到0的结果,所以你可以放心的写Label2.Caption:=adoquery1.fields.fields[0].asstring;
      

  4.   

    呵呵,我是小虫,咱们同类了,呵呵,正好我知道这个菜问题的答案:
    adoquery1.sql.clear;
    adoquery1.sql.add:='select count(*) as num_row from numcount where hgnum='''+trim(edit1.text)+'''';//你给这个列加一个别名上去,不过你的SQL语句还得改成这样,不然出错
    adoquery1.open;
    Label2.Caption:=adoquery1.FieldByName('num_row').asstring;// 这样写就可以了
      

  5.   

    adoquery1.sql.Text:='select count(*) from numcount where hgnum=trim(edit1.text)';
    God,你这SQL语句这样写可以执行?
      

  6.   

    adoquery1.sql.clear;
    adoquery1.sql.add('select count(*) as num_row from numcount where hgnum='''+trim(edit1.text)+'''');
    adoquery1.open;
    if adoquery1.RecordCount>0 then
     ladel1.caption:=inttostr(adoquery1.Count);
    else
     showmessage('没有满足条件的记录');
    end;
      

  7.   

    为了得到count(*)值,省略号处应该怎么写?
      Label2.Caption:=inttostr(adoquery1.RecordCount);没有符合条件的记录时,会不会有返回值?怎样得到这个返回值 ?
     
    同样会返回值,你只用判断adoquery1.fields[0].Asinteger>0 则表示有记录。
      

  8.   

    Label2.Caption:=adoquery1.fieldByName('numcount').AsString;
      

  9.   

    adoquery1.sql.clear;
    adoquery1.sql.ADD('select count(*) from numcount where hgnum=');
    adoquery1.sql.add(QuotedStr(trim(edit1.text));
    adoquery1.open;
    Label2.Caption:=adqQuery1.fields.fields[0].asString;
      

  10.   

    Delphi中的变量怎么写到SQL字符串中去了
      

  11.   

    winth adoquery1 do
      sql.clear;
      sql.add('select count(*) from numcount where hgnum=');
      sql.add(QuotedStr(trim(edit1.text));
      open;
    end;
    Label2.Caption:=adqQuery1.fields.fields[0].asString;
    在sql语句中没有什么数字或字符串的概念,都是以字符串处理的,所以按照sql语句的格式要在edit1.text上加上引号。
      

  12.   

    sql.add('select count(*) result from numcount where hgnum=');做成result,从result里面取值
      

  13.   

    inttostr(adoquery1.RecordCount);
      

  14.   

    ***********************
    在求记录数是,如果为空记录的话,会返回一条NULL值,当然在DELPHI中,NULL可以直接转换为0,但最好写成isnull(count(*),0) ,表示如果返回值是空,就替换为0。
    ***********************
    adoquery1.sql.clear;
    adoquery1.sql.Text:='select isnull(count(*),0) as num from numcount where hgnum='''+trim(edit1.text)+'''';
    adoquery1.open;Label2.Caption:=adoquery1.fieldbyname('num').asstring;
      

  15.   

    先给COUNT(*)加个别名,查询语句执行后就象连接普通的数据表,然后用adoquery1.fieldbyname('别名').value从数据集中读取数据放入标签控件就是了
      

  16.   

    TO  PaPaCong(小勇):   错,Count(*)在where条件所得出数据为空的时,COUNT的值是零,而不是空!
      

  17.   

    to 楼主 刚才发的帖子有一点错误,应加上一个‘begin’,不好意思。
    winth adoquery1 do
    begin
      sql.clear;
      sql.add('select count(*) from numcount where hgnum=');
      sql.add(QuotedStr(trim(edit1.text));
      open;
    end;
    Label2.Caption:=adqQuery1.fields.fields[0].asString;
    在sql语句中没有什么数字或字符串的概念,都是以字符串处理的,所以按照sql语句的格式要在edit1.text上加上引号。