sorry,我忘了一个‘#’
我在adoquery的sql中加入下列语句,
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add('select * from File where Filedate>=#2002-7-12 13:10:10# and Filedate<=#2002-7-19 10:10:10#');
adoquery1.open;
执行时,程序提示Parameter对象被不正确的定义,提供了不一致或不完整的信息。
我用的是access数据库。此sql语句在access中运行没有错误!真不知道是哪里的问题。
我在adoquery的sql中加入下列语句,
adoquery1.close;
adoquery1.sql.clear;
adoquery1.sql.add('select * from File where Filedate>=#2002-7-12 13:10:10# and Filedate<=#2002-7-19 10:10:10#');
adoquery1.open;
执行时,程序提示Parameter对象被不正确的定义,提供了不一致或不完整的信息。
我用的是access数据库。此sql语句在access中运行没有错误!真不知道是哪里的问题。
adoquery1.Parameters.ParamByName('StartDate').asDateTime:=var StartDate;
adoquery1.Parameters.ParamByName('EndDate').asDateTime:=var EndDate;
先写一个函数:
function CreateGlobalTSQLString(ADateTime: TDateTime): string;
var
strDestDateTime: string;
begin
strDestDateTime := FormatDateTime('yyyy-mm-dd hh:mm:ss.zzz', ADateTime);
Result := 'CONVERT(DATETIME,''' + strDestDateTime + ''',20)';
end;然后在生成sql语句时这样写:
ADODataSet1.CommandText := 'SELECT * FROM 订单 WHERE 订购日期 BETWEEN '+
CreateGlobalTSQLString(DateTimePicker1.Date) + ' AND ' +
CreateGlobalTSQLString(DateTimePicker2.Date) + ' ORDER BY 订购日期';这样就不用考虑DateTimePicker的日期格式和库中日期字段的格式的不同了。实际上这样处理就是告诉sql server我给你传进去的日期是什么格式的,剩下的事就是sql server的事了。我只在sql server 2000上测试通过。有兴趣的朋友可以试试其它的数据库。看能否帮到你!
你的时间怎么增加和更新的?
adoquery1.sql.clear;
adoquery1.sql.add('select * from File where Filedate>=#2002-7-12 13:10:10# and Filedate<=#2002-7-19 10:10:10#');
adoquery1.open;这样写法,因为SQL语句中间有:号,系统会把:后面的作为变量,要求赋值,所以出错。
只能直接到天。
adoquery1.sql.add('select * from File where Filedate>=#2002-7-12# and Filedate<=#2002-7-19#');或者用参数。
adoquery1.sql.add('select * from File where Filedate>=:BegDate and Filedate<=:EndDate');adoQuery1.Parameters.ParamByname('BegDate').DataType := ftDateTime;
adoQuery1.Parameters.ParamByname('BegDate').Value := StrToDateTime('2002-7-12 13:10:10');
adoQuery1.Parameters.ParamByname('EndDate').DataType := ftDateTime;
adoQuery1.Parameters.ParamByname('EndDate').Value := StrToDateTime('2002-7-19 10:10:10');
学习!!!
begin
name:='InputDate_1';
dataType:= ftdate;
Direction:= pdInput;
value:= #2001/01/10#;
end;// end with
with adoquer1.Parameters.AddParameter do
begin
name:='InputDate_2';
dataType:= ftdate;
Direction:= pdInput;
value:= #2002/09/10#;
end;// end with
select * from File where Filedate>=:InputDate_1 and Filedate<=:InputDate_2);
================================================================CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!★ 浏览帖子速度极快![建议系统使用ie5.5以上]。 ★ 多种帖子实现界面。
★ 保存帖子到本地[html格式]★ 监视您关注帖子的回复更新。
★ 可以直接发贴、回复帖子★ 采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录!
★ 支持在线检测程序升级情况,可及时获得程序更新的信息。★★ 签名 ●
可以在您的每个帖子的后面自动加上一个自己设计的签名哟。Http://www.ChinaOK.net/csdn/csdn.zip
Http://www.ChinaOK.net/csdn/csdn.rar
Http://www.ChinaOK.net/csdn/csdn.exe [自解压]
adoquery1.sql.add('select * from File where Filedate>=''2002-7-12 13:10:10'' and Filedate<=''2002-7-19 10:10:10''');
我想告诉你的是引证串‘yourString’=quote(yourString),