Query1.RecourdCount????????---在线提问
try
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('select * from docu_table where zh_num=:zhang and j_num=:jie');
Query1.ParamByName('zhang').Value:=trim(DBEdit1.Text);
Query1.ParamByName('jie').Value:=trim(DBEdit2.Text);
Query1.Prepare;
Query1.Open;
if Query1.FieldByName('zh_num').Value=trim(DBEdit1.Text) then showmessage('zh_j_docu_look for success!');//这一句被执行
if Query1.RecordCount>0 then//为什么这一句中却去执行else部分,怎样查看“RecordCount”的值?
begin
// Edit4.Text:=zhq.FieldValues['zh_num'];
showmessage('docu_ok');
end
else showmessage('docu_look for failure!');
except
showmessage('查询有误');
end;
问题点数:10、回复次数:12Top
1 楼duoduolao(多多劳)回复于 2005-05-09 09:14:05 得分 1
你showmessage(inttostr(query1.recordcount))看看recordcount的值是多少?
Top
2 楼jkx01whg(爱迪01)回复于 2005-05-09 09:37:42 得分 0
-1?
Maybe 查找有误...yun!Top
3 楼jkx01whg(爱迪01)回复于 2005-05-09 10:29:57 得分 0
请问query1.recordcount的值为何为零?
try
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('select * from docu_table where j_num=:jie');
Query1.ParamByName('jie').Value:=trim(DBEdit2.Text);
Query1.Prepare;
Query1.Open;
if Query1.FieldByName('zh_num').Value=trim(DBEdit1.Text) then showmessage('zh_j_docu_look for success!');//这一句被执行
if Query1.RecordCount>0 then//为什么这一句中却去执行else部分,怎样查看“RecordCount”的值?
begin
// Edit4.Text:=zhq.FieldValues['zh_num'];
showmessage('docu_ok');
end
else showmessage('docu_look for failure!');
except
showmessage('查询有误');
end;
Top
4 楼qizhanfeng(glacier)回复于 2005-05-09 10:42:38 得分 1
duoduolao(多多劳) ( deTop
5 楼yczyk(有鬼:泪眼问花花不语,乱红飞过千秋去)回复于 2005-05-09 13:18:12 得分 3
Delphi在线帮助中是这样说的:
The dataset component must be active for RecordCount to provide a valid number. Should ADO not be able to determine that actual number of rows, RecordCount will return a value of negative one (-1).
就是说,如果一条记录都没有就是0,如果ado检测不到有多少记录时就为-1,否则就是实际查到的记录数!
一般是用recordcount>0表示得到了记录!Top
6 楼yuejun(飞天红猪侠)回复于 2005-05-09 14:36:39 得分 1
if not Query1.eof thenTop
7 楼jkx01whg(爱迪01)回复于 2005-05-09 18:30:01 得分 0
if not Query1.eof then..//条件为真,但是recordcount还是小于0,那是哪儿错啦??????Top
8 楼zhxfzhxf1(zhxfzhxf1)回复于 2005-05-09 21:11:30 得分 1
同意 yczyk(有鬼:泪眼问花花不语,乱红飞过千秋去)
我一般是先执行 select count(*) from xxx where xx,之后再判断的Top
9 楼jkx01whg(爱迪01)回复于 2005-05-10 19:04:45 得分 0
问题依旧没解决,急死人了Top
10 楼bxyqt(碧血银枪)回复于 2005-05-12 16:10:12 得分 3
呵呵,代码如下更改:
try
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('select * from docu_table where zh_num=:zhang and j_num=:jie');
Query1.ParamByName('zhang').Value:=trim(DBEdit1.Text);
Query1.ParamByName('jie').Value:=trim(DBEdit2.Text);
Query1.Prepare;
Query1.Open;
if Query1.FieldByName('zh_num').asstring=trim(DBEdit1.Text) then showmessage('zh_j_docu_look for success!');//这一句被执行
if Query1.RecordCount>0 then//为什么这一句中却去执行else部分,怎样查看“RecordCount”的值?
begin
// Edit4.Text:=zhq.FieldValues['zh_num'];
showmessage('记录条数:'+inttostr(Query1.RecordCount));
end
else showmessage('docu_look for failure!');
except
showmessage('查询有误');
end;
Top
11 楼bxyqt(碧血银枪)回复于 2005-05-12 16:18:04 得分 0
对不起,我还是说错了。
请将.Value全替换为.asstring。
将记录数查询改为:showmessage('记录条数:'+inttostr(Query1.RecordCount));Top
12 楼bxyqt(碧血银枪)回复于 2005-05-12 16:40:52 得分 0
这样吧,简化一下你的代码:
try
Query1.Close; Query1.SQL.Clear;
Query1.SQL.Add('select * from docu_table where zh_num='''+trim(DBEdit1.Text)+''' and j_num='''+trim(DBEdit2.Text)+'''');
Query1.Open;
if Query1.FieldByName('zh_num').asstring=trim(DBEdit1.Text) then showmessage('zh_j_docu_look for success!');
if Query1.RecordCount>0 then
begin
showmessage(inttostr(Query1.RecordCount));
end
else showmessage('docu_look for failure!');
except
showmessage('查询有误');
end;
Top




