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中运行没有错误!真不知道是哪里的问题。

解决方案 »

  1.   

    使用 between;adoquery1.sql.add('select * from File where Filedate between :StartDate and :EndDate');
    adoquery1.Parameters.ParamByName('StartDate').asDateTime:=var StartDate;
    adoquery1.Parameters.ParamByName('EndDate').asDateTime:=var EndDate;
      

  2.   

    编写国际化 Transact-SQL 语句--日期、时间问题 我在Sql Server 2000的联机帮助中看到《编写国际化 Transact-SQL 语句》这篇文章,觉得很有用,其中提到数据库中的日期时间问题。下面是我在delphi中的尝试:
    先写一个函数:
    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上测试通过。有兴趣的朋友可以试试其它的数据库。看能否帮到你!
      

  3.   

    你是否使用的datetimepicker控件?
    你的时间怎么增加和更新的?
      

  4.   

    btw,你在sql语句中用#号是什么意思?
      

  5.   

    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;这样写法,因为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');
      

  6.   

    不要使用直接的内容做为条件,使用变量传输,不是一定要用between吧??
    学习!!!
      

  7.   

    哈哈,你们都错了,把adoquery的ParamCheck属性改成False后,一切Ok!
      

  8.   

    哈哈,你们都错了,把adoquery的ParamCheck属性改成False后,一切Ok!
      

  9.   

    adoquery的ParamCheck属性改成False后,可以運行嗎?
      

  10.   

    写成 select * from File where Filedate>=''2002-7-12 13:10:10'' and Filedate<=''2002-7-19 10:10:10''
      

  11.   

    写成 select * from File where Filedate>=''2002-7-12 13:10:10'' and Filedate<=''2002-7-19 10:10:10''
      

  12.   

    with adoquer1.Parameters.AddParameter do
    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    [自解压]
      

  13.   

    请试一下(access 中的日期庸##表示,SQLSERVER中用''):
    adoquery1.sql.add('select  *  from  File  where  Filedate>=''2002-7-12  13:10:10''  and  Filedate<=''2002-7-19  10:10:10''');  
      

  14.   

    恭喜楼主,找到答案,
    我想告诉你的是引证串‘yourString’=quote(yourString),
      

  15.   

    各位注意,我用的是access数据库,日期时间的两头必须加‘#’号