access表中日期类型字段:时间sqlstr:='select * from 表 where 时间 between '''+edit6.text+'%'' and '''+edit7.text+'%'''  ;   dm.adoquery1.Close;
   dm.adoquery1.SQL.Clear;
   dm.adoquery1.SQL.Add(sqlstr);
   dm.adoquery1.open;
输入2004-5-1和2004-6-30运行出错,提示表达式数据类型不匹配

解决方案 »

  1.   

    主  题:  有没有把字符型2004-5-1转化成日期类型的函数啊  strtodate
      

  2.   

    sqlstr:='select * from 表 where 时间 between '''+edit6.text+'%'' and '''+edit7.text+'%'''  ;
    把%去掉,手动添加时间字符串!
    如:
    sqlstr:='select * from 表 where 时间 between '''+edit6.text+' 00:00:00'' and '''+edit7.text+' 23:59:59'''  ;
      

  3.   

    改用参数吧.用引号不小心就会数错.
    函数用这个.
    StrToDateTime(const S: string): TDateTime;
      

  4.   

    to: gzhk(gz) StrToDateTime(const S: string): TDateTime;这个怎么用啊
      

  5.   

    sqlstr:='select * from 表 where 时间 between '+StrToDateTime(edit6.text)+ 'and '+StrToDateTime(edit7.text) 
      

  6.   

    你的问题问的有问题!因为在数据库里保存的时候 所谓的日期时间字段保存的不仅仅是时间或者日期 他们是一起保存的 所以在查询的时候你需要把这个字段的值用特有的函数分离开来!不同的数据库写法是不一样的 如果是SQL SERVER  用select * from 表 where
    convert(char(10),日期,102)='2004-05-01'  求时间就把102修改为108
    如果是Access的话 就要用DataValue和TimeValue 记得 日期和时间不能写在一起查询 要分开!
      

  7.   

    dm.adoquery1.Close;
       dm.adoquery1.SQL.Clear;
       dm.adoquery1.SQL.Add('select * from table where time between :date_begin and :date_end ');
       parameters.ParamByName('date_begin').Value := edit6.text;
       parameters.ParamByName('date_end').Value   := edit7.text;
       dm.adoquery1.open;
      

  8.   

    在sql server 中不用把日期和时间分开的,如果你赋值是 2004-05-01
    会默认为是 2004-05-01 00:00:00
      

  9.   

    呵呵~~~
    问题还是可以解决的。
    1、检查输入的字符是否日期格式:
    Try
       strtodate(edit6.text);
       strtodate(edit6.text);
    except
       showmessage('日期格式出错,请重新输入。');
       exit;
    end;
    2、检查数据库中“时间”字段是否为日期类型。如果是才能用between,如果是字符类型就肯定出错啦。
    3、在写sql语言时,先把字符转为日期格式,那么就会有标准的日期格式。然后再转换成str格式。
    例如:sqlstr:='select * from 表 where 时间 between '''+datetostr(strtodate(edit6.text))+''' and '''+datetostr(strtodate(edit7.text))+'''';
    4、不需要加%号。
      
      

  10.   

    如果是access的话 要这样写
    select * from 仓库入库管理 where DateValue(入库日期) between '''+edit6.text+''' and ''' ecit7.text +'''';sql-server
    select * from 仓库入库管理 where convert(char(10),入库日期,102) between '''+edit6.text+''' and ''' ecit7.text +'''';
      

  11.   


    改为
    sqlstr:='select * from 表 where 时间 between '''+strtodate(edit6.text)+''' and '''+strtodate(edit7.text)+'''';