DELPHI+ACCESS
程序如下:
self.adoquery1.close;
self.adoquery1.sql.clear;
self.adoquery1.sql.add('select * yhxx');
self.adoquery1.sql.add('where rq='''+self.label1.caption+'''');
self.qdoquery1.prepear;
self.adoquery1.open;注:'rq'字段为日期/时间类型,短日期类型。

解决方案 »

  1.   

    如果是日期
    select * from 报告单 where 报告日期=#1979-10-18# 如果是时间
    时间里面要用两个:号,
    select * from 报告单 where 报告日期=#1979-10-18 16::38::00#
      

  2.   

    还有 你的
    self.adoquery1.sql.add('select * yhxx');
    是什么?写错了吧?
      

  3.   

    在确保self.label1.caption为正确日期的情况下,将下句
    self.adoquery1.sql.add('where rq='''+self.label1.caption+'''');
    改为
    self.adoquery1.sql.add('where rq='#'+self.label1.caption+'#');
    因为在Access中日期型可写为#2003-12-17#,而在SQL Server中,
    你的语句如果没有语法错误,则可能是正确的。
      

  4.   

    self.adoquery1.sql.add('select * from yhxx');
    self.adoquery1.sql.add('where rq='#'+self.label1.caption+'#');
      

  5.   

    同意楼上,但是建议楼主不要用动态生成SQL语句。而去用参数的形式查询数据。小心你的数据被删除掉!!!!!
      

  6.   

    //查询数据库中的日期时间类型前要先把数据库中的日期类型转换成指定的格式才能进行
    //比较
    //转换用SQL函数CONVERT
    //三个参数: 1、转换成什么类型的数据和长度
    //2、要转换的数据或字段
    //3、转换的数据格式self.adoquery1.close;
    self.adoquery1.sql.clear;
    self.adoquery1.sql.add('SELECT * FROM yhxx');
    self.adoquery1.sql.add('WHERE CONVERT(VARCHAR, rq, 120) = ' + #39 +
         self.label1.caption + #39);
    self.qdoquery1.prepear;
    self.adoquery1.open;=================================================================================
    //CONVERT(VARCHAR, rq, 120) 是把日期类型字段rq转换成字符串,字符串格式为
    //2003-12-17 13:27:14格式的字符串//如果要用到模糊搜索就用
    //self.adoquery1.sql.add('WHERE CONVERT(VARCHAR, rq, 120) LIKE ' + #39 + '%' +
    //     self.label1.caption + '%' + #39);
      

  7.   

    如果只要日期就用以下方法
    CONVERT(VARCHAR(10), rq, 120)
      

  8.   

    self.adoquery1.close;
    self.adoquery1.sql.clear;
    self.adoquery1.sql.add('select * yhxx');
    self.adoquery1.sql.add('where rq= #'+self.label1.caption+'#');
    self.qdoquery1.prepear;
    self.adoquery1.open;注:'rq'字段为日期/时间类型,短日期类型
      

  9.   

    DELPHI+ACCESS
    程序如下:
    self.adoquery1.close;
    self.adoquery1.sql.clear;
    self.adoquery1.sql.add('select * from yhxx ');  // 
    self.adoquery1.sql.add(' where rq='''+self.label1.caption+''''); 
    // 表名(yhxx)和where 应由至少一个空格;
    self.qdoquery1.prepear;
    self.adoquery1.open;注:'rq'字段为日期/时间类型,短日期类型。
      

  10.   

    self.adoquery1.close;
    self.adoquery1.sql.clear;
    self.adoquery1.sql.add('select * from yhxx');
    self.adoquery1.sql.add('where to_char(rq,'+'''yyymmdd'''+')=''''+self.label1.caption+'''');
    self.qdoquery1.prepear;
    self.adoquery1.open;
      

  11.   

    同意 cxreal 的说法,  changly00 说的那是oracle里面的语法。
    或者你用动态sql参数, 就不需要考虑数据库类型的问题。