两个使用ADO查询的问题。(100分)

  • 主题发起人 主题发起人 wwwdatao
  • 开始时间 开始时间
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('号码出现重复')

以上的代码在程序运行时出现 当我领用的起号码等于库中已有记录的终止号码时,仍然能够领用。

请大家帮忙指出我的错误,或是给个更好的查询方法。
 
问题1 : :s 只能是代表字段的值 ,不能代表别的内容. 就是这个不等同于 一个字符串
问题2: 没看懂 .在 cfnum>0 的时候,不是只有一个show 的动作吗? 那只能show 这个动作表达出来啊? 你没做任何中止的事情啊
 
unit_rk 的表结构是什么样的?
存储的是什么内容?
 
问题2:select count(*) as mycou from unit_rk where (start_num>=:startn and start_num<=:endn) or (end_num>=:startn and end_num<=:endn) or (start_num<:startn and end_num>:endn)
或者
select count(*) as mycou from unit_rk where (start_num<=:startn and end_num>=:startn) or (start_num<=:endn and end_num>=:endn)
 
使用两个between 可以不?

start_num between :s and :s1 or end_num between :s and :s1
 
第二个问题写得太乱了,有点理不清
 

Parameters.parambyname('startn').Value :=rzdbnumericedit1.IntValue;
前加代码
Parameters.Refresh;
 
==========

Parameters.parambyname('startn').Value :=rzdbnumericedit1.IntValue;
前加代码
Parameters.Refresh;
==============
这样做有甚么意义吗?刷新一次参数
 
没有人回答问题了啊??????是不是要加些分才可以噢?
 
ADO连接带参数,好象是要Refresh一下,参数才可以传递。你在代码前Refresh后,看程序是否正常了吧。
 
来自:tomjerry, 时间:2006-10-28 16:41:42, ID:3608689
ADO连接带参数,好象是要Refresh一下,参数才可以传递。你在代码前Refresh后,看程序是否正常了吧。
================
试过了,和这个没有关系,,
 

Similar threads

后退
顶部