还有如下问题?
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)';语句没有符合条件的记录时,会不会有返回值?怎样得到这个返回值 ?
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)';语句没有符合条件的记录时,会不会有返回值?怎样得到这个返回值 ?
但可判断adoquery1.RecordCount这个值,
如果为0
即为没有满足条件的记录
2。没有记录的时候会得到0的结果,所以你可以放心的写Label2.Caption:=adoquery1.fields.fields[0].asstring;
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;// 这样写就可以了
God,你这SQL语句这样写可以执行?
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;
Label2.Caption:=inttostr(adoquery1.RecordCount);没有符合条件的记录时,会不会有返回值?怎样得到这个返回值 ?
同样会返回值,你只用判断adoquery1.fields[0].Asinteger>0 则表示有记录。
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;
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上加上引号。
在求记录数是,如果为空记录的话,会返回一条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;
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上加上引号。