ACCESS数据库,日期格式是2004-07-09 08:08:08,是YYYY-MM-DD HH:MM:SS的格式,现在我用二个datetimepicker控件选择日期,然后搜索数据库里面在这二个日期之间的数据,程序如下:
  dataform.Qin.Close;//Qin是SQL查询的控件
  dataform.Qin.SQL.Clear;
//in_thing 是要查找的数据库  in_time是日期,格式上面所说
  dataform.Qin.SQL.Add('select * from in_thing where in_time between '+quotedstr('#'+datetimepicker1.Date+'#')+' and '+quotedstr('#'+datetimepicker2.Date+'#')+' order by id desc');  try
    dataform.Qin.Open;
  except
    showmessage('查找失败!');
    exit;
  end;谢谢各位了,在线等候,OK马上给分。

解决方案 »

  1.   

    dataform.Qin.SQL.Add('select * from in_thing where in_time >= ''' + DateToStr(datetimepicker1.Date)+''' and in_time < '''+DateToStr(datetimepicker2.Date)+''' order by id desc');
      

  2.   

    谢谢,不过还是不行,找不到。请问多一下,'select * from in_thing where in_time >= ''' ,这里为什么要'''这个三点啊,一点'不行吗??
      

  3.   

    WSprg() ,上面的程序说类型不配
      

  4.   

    laiyiling(最熟悉的陌生人) 查过已前的贴子了,不明。。只有二贴,但是有点不同于我这个。
      

  5.   

    三个'''表示一个',必须这样写。
    如果用参数写也行:
    dataform.Qin.SQL.Add('select * from in_thing where in_time >= :sdate and in_time < =;edate order by id desc');
    dataform.Qin.parambyname('sdate').asdatetime=strtodatetime(edit1.text);
    dataform.Qin.parambyname('edate').asdatetime=strtodatetime(edit2.text);dataform.Qin.open;
      

  6.   

    将程序生成的sql语句到access中调试一下,看有什么问题。
      

  7.   

    TO: hhnick(nick) 我试试看。
    TO: chwdong(chwdong)。开始我也想用between....and.但是老出错。
      

  8.   

    dataform.Qin.Close;//Qin是SQL查询的控件
      dataform.Qin.SQL.Clear;
    //in_thing 是要查找的数据库  in_time是日期,格式上面所说
      dataform.Qin.SQL.Add('select * from in_thing where in_time between '''+'''#'+datetimepicker1.Date+'#'''+' and '+'''#'+datetimepicker2.Date+'#'''+' order by id desc');  try
        dataform.Qin.Open;
      except
        showmessage('查找失败!');
        exit;
      end;
    去掉两个转换函数,还有在引号内,两个单引号才等于一个单引号。
      

  9.   

    谢谢 gyj_china(透明),我试试。
      

  10.   

    正解:
     dataform.Qin.SQL.Add('select * from in_thing where in_time between ''#'+datetostr(datetimepicker1.Date)+'#'' and ''#'+datetostr(datetimepicker2.Date)+'#'' order by id desc');
      

  11.   

    谢谢大家了,结果我试出来了。
    是这样的:
    dataform.Qin.SQL.Add('select * from in_thing where in_time between '+'#'+datetostr(datetimepicker1.Date)+'#'+' and '+'#'+datetostr(datetimepicker2.Date)+'#'+' order by id desc');