请问以下代码在delphi6.0+BDE+paradox下能够编译通过,而在ADO+ACCESS下则通不过是什么原因?(30分)

  • 主题发起人 主题发起人 libaoliang
  • 开始时间 开始时间
L

libaoliang

Unregistered / Unconfirmed
GUEST, unregistred user!
请问以下代码在delphi6.0+BDE+paradox下能够编译通过,而在
delphi6.0+ADO+access下则编译无法通过,这是什么原因?

a1:='select cpmc as 产品名称,sum(zpzl) as 装坯数,sum(cpl) as 成品量 from cpk where (rq between :rq1 and :rq2) group by cpmc';
query1.close;
query1.sql.clear;
query1.sql.add(a1);
query1.parambyname('rq1').asdate:=datetimepicker1.date;
query1.parambyname('rq2').asdate:=datetimepicker2.date;
query1.open;

a1:='select cpmc as 产品名称,sum(zpzl) as 装坯数,sum(cpl) as 成品量 from cpk where (rq between :rq1 and :rq2) group by cpmc';
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add(a1);
adoquery1.parambyname('rq1').asdate:=datetimepicker1.date;
adoquery1.parambyname('rq2').asdate:=datetimepicker2.date;
adoquery1.open;
 
日期的格式各种数据都有所差异
Access中需要将日期加上"#"界定符
字段用[]包含
ACCESS中的日期查询
注意:ACCESS中的日期时间分隔符是#而不是引号
Select * From Tab1 Where [Date]>#2002-1-1#;
在DELPHI中我这样用
SQL.Add(Format(
'Select * From Tab1 Where [Date]>#%s#;',
[DateToStr(Date)]));

 
adoquery1.parambyname('rq1').asdate:=datetimepicker1.date;
adoquery1.parambyname('rq2').asdate:=datetimepicker2.date;
改为
adoquery1.parambyname('rq1').value:=datetimepicker1.date;
adoquery1.parambyname('rq2').value:=datetimepicker2.date;
ADO的参数没有as...什么的
 
我改为下面的代码,可还是不对:
adoquery1.Close;
adoquery1.sql.clear;
s1:='select gd as 工段,xm as 违纪人,tl as 违纪内容,sum(je) as 罚款金额 from khjl where (rq between :rq1 and :rq2) group by gd,xm,tl';
adoquery1.sql.add(s1);
adoquery1.parambyname('rq1').value:=datetimepicker1.date;
adoquery1.parambyname('rq2').value:=datetimepicker2.date;
adoquery1.open;
系统提示的错误信息是:
[Error] Unittj.pas(123): Undeclared identifier: 'parambyname'
[Error] Unittj.pas(123): Missing operator or semicolon
[Error] Unittj.pas(124): Undeclared identifier: 'parambyname'
[Error] Unittj.pas(124): Missing operator or semicolon
[Fatal Error] khmis.dpr(18): Could not compile used unit 'Unittj.pas'
请再检查一下原因!
 
改为下列时能编译通过,但执行时提示参数越界,
adoquery1.Close;
adoquery1.sql.clear;
s1:='select gd as 工段,xm as 违纪人,tl as 违纪内容,sum(je) as 罚款金额 from khjl where (rq between :rq1 and :rq2) group by gd,xm,tl';
adoquery1.sql.add(s1);
adoquery1.parameters[0].value:=datetimepicker1.date;
adoquery1.parameters[1].value:=datetimepicker2.date;
adoquery1.open;
 
adoquery1.sql.add(s1);
adoquery1.Prepared := True;
adoquery1.parameters[0].value:=datetimepicker1.date;
adoquery1.parameters[1].value:=datetimepicker2.date;
adoquery1.open;
 
还是不行,
procedure Ttj.BitBtn1Click(Sender: TObject);
var s1:string;
begin
adoquery1.Close;
adoquery1.sql.clear;
s1:='select gd as 工段,xm as 违纪人,tl as 违纪内容,sum(je) as 罚款金额 from khjl where (rq between :rq1 and :rq2) group by gd,xm,tl';
adoquery1.sql.add(s1);
adoquery1.Prepared:=True;
adoquery1.parameters[0].value:=datetimepicker1.date;
adoquery1.parameters[1].value:=datetimepicker2.date;
adoquery1.open;
end;
错误信息是:标准表达式中数据类型不匹配
 
adoquery1.parameters[0].AsDateTime := ...
如果还是不行,改成 rq>=: and rq<=: 试一下
如果还不行,就不要使用参数了
 
我去试一下,
不过不使用动态参数怎么能行,
需要根据用户的选择范围进行统计啊!
adoquery的动态参数格式究竟是怎样的,
为何与BDE+paradox的不一样
 
我已经试过,
都不行,
我用的是ado+access
难道adoquery的动态参数就无法设置吗?
关于日期字段的?
 
已经在另一贴中解决了!
 
后退
顶部