W
wwwdatao
Unregistered / Unconfirmed
GUEST, unregistred user!
问题1
--------
我有如下一段代码
with dm.ADOQuery1 do
begin
close;
sql.Clear ;
sql.Add('select count(*) as mycou from unit_rk where ( :startn>=start_num and :startn<=end_num) or ( :endn<=end_num and :endn>=start_num)');
Parameters.parambyname('startn').Value :=rzdbnumericedit1.IntValue;
Parameters.parambyname('endn').Value :=rzdbnumericedit2.IntValue;
open;
cfnum:=FieldByName('mycou').AsInteger ;
close;
end;
执行以上代码会提示参数'startn'无法找到
如果将第5行更改为下面这种形式就可以正常使用。
sql.Add('select count(*) as mycou from unit_rk where (start_num>=:startn and start_num<=:endn) or (end_num>=:startn and end_num<=:endn)');
我的问题是难道:startn这个参数就不能直接放在前面而必须放运算符号后面才能被找到??
我在使用ODAC数据控件的时候,第一种情况就能过正常使用。ADO有甚么不同吗?
问题2
=====================
现有一发票领用表 unit_rk 其中 start_num 字段记录发票起始号码,end_num字段记录发票终止号码。
在发票领用时输入发票起始号码startn,发票终止号码endn。
我通过下面的SQL语句查询现在领用的发票号码是否和以前库中的号码有重号。
with dm.ADOQuery1 do
begin
close;
sql.Clear ;
sql.Add('select count(*) as mycou from unit_rk where (start_num>=:startn and start_num<=:endn) or (end_num>=:startn and end_num<=:endn)');
Parameters.parambyname('startn').Value :=rzdbnumericedit1.IntValue;
Parameters.parambyname('endn').Value :=rzdbnumericedit2.IntValue;
open;
cfnum:=FieldByName('mycou').AsInteger ;
close;
end;
if cfnum>0 then
showmessage('号码出现重复')
以上的代码在程序运行时出现 当我领用的起号码等于库中已有记录的终止号码时,仍然能够领用。
请大家帮忙指出我的错误,或是给个更好的查询方法。
--------
我有如下一段代码
with dm.ADOQuery1 do
begin
close;
sql.Clear ;
sql.Add('select count(*) as mycou from unit_rk where ( :startn>=start_num and :startn<=end_num) or ( :endn<=end_num and :endn>=start_num)');
Parameters.parambyname('startn').Value :=rzdbnumericedit1.IntValue;
Parameters.parambyname('endn').Value :=rzdbnumericedit2.IntValue;
open;
cfnum:=FieldByName('mycou').AsInteger ;
close;
end;
执行以上代码会提示参数'startn'无法找到
如果将第5行更改为下面这种形式就可以正常使用。
sql.Add('select count(*) as mycou from unit_rk where (start_num>=:startn and start_num<=:endn) or (end_num>=:startn and end_num<=:endn)');
我的问题是难道:startn这个参数就不能直接放在前面而必须放运算符号后面才能被找到??
我在使用ODAC数据控件的时候,第一种情况就能过正常使用。ADO有甚么不同吗?
问题2
=====================
现有一发票领用表 unit_rk 其中 start_num 字段记录发票起始号码,end_num字段记录发票终止号码。
在发票领用时输入发票起始号码startn,发票终止号码endn。
我通过下面的SQL语句查询现在领用的发票号码是否和以前库中的号码有重号。
with dm.ADOQuery1 do
begin
close;
sql.Clear ;
sql.Add('select count(*) as mycou from unit_rk where (start_num>=:startn and start_num<=:endn) or (end_num>=:startn and end_num<=:endn)');
Parameters.parambyname('startn').Value :=rzdbnumericedit1.IntValue;
Parameters.parambyname('endn').Value :=rzdbnumericedit2.IntValue;
open;
cfnum:=FieldByName('mycou').AsInteger ;
close;
end;
if cfnum>0 then
showmessage('号码出现重复')
以上的代码在程序运行时出现 当我领用的起号码等于库中已有记录的终止号码时,仍然能够领用。
请大家帮忙指出我的错误,或是给个更好的查询方法。