SQL :
query3.close;
query3.SQL.Clear;
query3.SQL.add('SELECT  * FROM tablename where fzrq between "'+datetostr(DateTimePicker1.date)+'" and "'+datetostr(DateTimePicker2.date)+'" order by fzrq');查询结果没有数据(数据表中有符合条件的数据)
如果在DateTimePicker1.date处直接写日期可以查出结果,
请解决。。

解决方案 »

  1.   

    我注意看了一下你的程序,不知道你在 '" and "' 等处写的是单引号还是双引号,是双引号
    那就要写成二个单引号,还有,有一点要注意,日期格式应写成与数据库内的日期字段格式相同
    才能查到数据,用 formatdatetime
      

  2.   


      DateTimePicker1.DateTime
    试试看
      

  3.   

    在query3.sql.add一句后面使用断点,看看sql的内容,我估计有一个条件种date都没有值。可能是因为tdatetimepicker的原因。
    在调用qery3.close时把焦点从datetimepicker出移开看看,比如调用button1.setfocus.
      

  4.   

    你这样竟然不报错啊,我在access 97(谁在向俺扔鸡蛋)里写成这样会因为日期型和字符串不兼容而报错,我这加个CDate转换一下就行了,看你用什么库然后用相应的转换函数转换一下试试先。
      

  5.   

    我用的是DB 数据表,datetimepicker是有值的,会不会是datetimepicker的日期格式?年分好象是两位的,不知道如何解决?
      

  6.   

    query3.close;
    query3.SQL.Clear;
    query3.SQL.add('SELECT  * FROM tablename where fzrq>='''+datetostr(DateTimePicker1.date)+''' and  fzrq<='''+datetostr(DateTimePicker2.date)+''' order by fzrq');
      

  7.   

    query3.SQL.add('SELECT  * FROM tablename where fzrq between "'+datetostr(DateTimePicker1.date)+'" and "'+datetostr(DateTimePicker2.date)+'" order by fzrq');try:Query3.SQL.add('select * from tablename where fzrq between :D1 and :D2 order by fzrq');
    Query3.ParamByName('D1').AsDateTime := DateTimePicker1.Date;
    Query3.ParamByName('D2').AsDateTime := DateTimePicker2.Date;老兄做的程序 fzrq 是不是发证日期字段呀?我看着很眼熟,呵呵!
      

  8.   

    CloneCenter(复制中心)你的是对的,我早试过了。
      

  9.   

    type mismath in espression
      

  10.   

    query3.SQL.add('SELECT  * FROM tablename where fzrq between '+''''+FormatDateTime(DateTimePicker1.date)+''''+' and '+''''+FormatDateTime(DateTimePicker2.date)+''''+' order by fzrq');
      

  11.   

    query3.SQL.add('SELECT  * FROM tablename where fzrq between '+''''+FormatDateTime('YYYY-mm-dd',DateTimePicker1.date)+''''+' and '+''''+FormatDateTime('YYYY-MM-DD',DateTimePicker2.date)+''''+' order by fzrq');