一条菜虫问一个很菜的问题?

downkey 2003-09-14 07:59:20
还有如下问题?
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)';语句没有符合条件的记录时,会不会有返回值?怎样得到这个返回值 ?
...全文
106 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
downkey 2003-09-16
  • 打赏
  • 举报
回复
多谢各位,小生有礼,问题得以解决。
多谢发分罗
wzds2000 2003-09-15
  • 打赏
  • 举报
回复
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上加上引号。
superlionet 2003-09-15
  • 打赏
  • 举报
回复
应该不是很难的问题吧? 上面大家的方法都应该可以解决呀。
WuLoveXue 2003-09-15
  • 打赏
  • 举报
回复
TO PaPaCong(小勇):

错,Count(*)在where条件所得出数据为空的时,COUNT的值是零,而不是空!
2353939 2003-09-15
  • 打赏
  • 举报
回复
先给COUNT(*)加个别名,查询语句执行后就象连接普通的数据表,

然后用adoquery1.fieldbyname('别名').value从数据集中读取数据

放入标签控件就是了
PaPaCong 2003-09-15
  • 打赏
  • 举报
回复
***********************
在求记录数是,如果为空记录的话,会返回一条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;
fhuibo 2003-09-15
  • 打赏
  • 举报
回复
inttostr(adoquery1.RecordCount);
sy_315 2003-09-15
  • 打赏
  • 举报
回复
sql.add('select count(*) result from numcount where hgnum=');

做成result,从result里面取值
wzds2000 2003-09-15
  • 打赏
  • 举报
回复
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上加上引号。
DelphiBird 2003-09-14
  • 打赏
  • 举报
回复
Delphi中的变量怎么写到SQL字符串中去了
kingofghost 2003-09-14
  • 打赏
  • 举报
回复
现在没有时间,呵呵,等有时间再给你试试看怎么写哈,不过好像上面的方法有几个比较管用
JustJune 2003-09-14
  • 打赏
  • 举报
回复
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;
newnewworm 2003-09-14
  • 打赏
  • 举报
回复
Label2.Caption:=adoquery1.fieldByName('numcount').AsString;
PrgmLover 2003-09-14
  • 打赏
  • 举报
回复
为了得到count(*)值,省略号处应该怎么写?
Label2.Caption:=inttostr(adoquery1.RecordCount);

没有符合条件的记录时,会不会有返回值?怎样得到这个返回值 ?

同样会返回值,你只用判断adoquery1.fields[0].Asinteger>0 则表示有记录。
yanhuizen 2003-09-14
  • 打赏
  • 举报
回复
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;
FrameSniper 2003-09-14
  • 打赏
  • 举报
回复
adoquery1.sql.Text:='select count(*) from numcount where hgnum=trim(edit1.text)';


God,你这SQL语句这样写可以执行?
kingecg 2003-09-14
  • 打赏
  • 举报
回复
fields[0].asstring
Drate 2003-09-14
  • 打赏
  • 举报
回复
呵呵,我是小虫,咱们同类了,呵呵,正好我知道这个菜问题的答案:
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;// 这样写就可以了
ZyxIp 2003-09-14
  • 打赏
  • 举报
回复
我是一只小小鸟
WuLoveXue 2003-09-14
  • 打赏
  • 举报
回复
1。adoquery1.fields.fields[0].asstring,不过最好建议你给count(*) 取个别名!
2。没有记录的时候会得到0的结果,所以你可以放心的写Label2.Caption:=adoquery1.fields.fields[0].asstring;
加载更多回复(2)

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧