是这样检测ADOQuery返回的记录为空的数据集的吗?(10分)

G

gmwing

Unregistered / Unconfirmed
GUEST, unregistred user!
with ADOQuery1 do
begin
close;
sql.clear;
sql.add('select * form bm' where 条件);
open;
end;
if ADOQuery1.recordcount=0 then
showmessage(‘没有合符条件的记录存在!’)
else
showmessage(‘合符条件的记录有:’+inttostr(ADOQuery1.recordcount)+'条');
 
只要SQL语句是正确的,对
 
还有其它方法吗?
 
我用ASP做访问access数据库时用 if not (rs.eof and rs.bof) then
 
运行时这句:sql.add('select * form bm' where 条件)有错
若没参数这样:sql.add('select * form bm where 条件'),
自己多调试一下.
 
if ADOQuery1.IsEmpty then ...
 
我是想清楚是不是这样检测的?多谢!
sql.add('select * form bm' where 条件)是我打字错了,
应该是:sql.add('select * form bm where 条件') ^_^
 
不要用RocordCount
 
那!用什么????
 
use this:

if query1.field[0].asstring='' then
showmessage('NUll')
 
对,不要用RecorderCount,容易出错,尤其是在表是空的时候。用BAByboom的方法就可以了
 
尽量不要用recordcount,它有时候不能正确返回记录的个数,可以用EOF和BOF来判断,就像firstlove说的那样。
 
if ADOQuery1.IsEmpty then ...
 
人在昆明的回答,我赞同,既然有了这个属性为什么不用呢
 
用QUEry.Isempty检测
 
同意楼上
 
用isempty 是最准确了,recordercount 有时不准确
 
recordcount不准确是ADODB单元的一个Bug
如果你想让他准确,就自己修改一下那个单元
 
ADOQuery1.IsEmpty 属性也是判断是否为空
 
顶部