aqryid是TADOQuery
aqryid表的SQL属性如下:
select jyh from t_saledet
where rq=:vdate
运行下面代码时
with aqryid do
    begin
      Close ;
       Parameters.ParamByName('vdate').Value := formatdatetime('yyyy,mm,dd',DBDateTimeEditEh1.value) ;
      open;
    end;
发生错误提示:
从字符串转为datetime时发生错误
怎么办?谢谢!!

解决方案 »

  1.   

    什么数据库,字段类型是什么,改一下试试
    formatdatetime('yyyy-mm-dd', DBDateTimeEditEh1.value) ;
      

  2.   

    如果是TDateTime类型的字段,则可以直接赋值:Parameters.ParamByName('vdate').AsDateTime := DBDateTimeEditEh1.value
      

  3.   

    我用的是sql2000,是从ACCESS转换过来的.在中没问题
      

  4.   

    尽可能用'yyyy-mm-dd',SQLSERVER默认是用-作间隔符号。
      

  5.   

    用formatdatetime('yyyy-mm-dd',日期)试试
      

  6.   

    類似這樣  if (Trim(cxtextedit1.Text)='') and (Trim(cxDateEdit1.Text)<>'') then
      begin
        qry_xgbb.Close;
        qry_xgbb.sql.Clear;
        qry_xgbb.sql.Add( ' select c.*,case when c.jh=1  then ''A區警衛室'' when c.jh=2  then ''B區警衛室'' when c.jh=3  then ''回收區'' ' );
        qry_xgbb.sql.Add( ' when c.jh=4  then ''F棟宿舍'' when c.jh=5  then ''C棟宿舍'' when c.jh=6  then ''電工房'' ' );
        qry_xgbb.sql.Add( ' when c.jh=7  then ''B棟宿舍'' when c.jh=8  then ''A棟宿舍'' when c.jh=9  then ''西側警衛室'' when c.jh=10  then ''A區材料倉'' end as dd ' );
        qry_xgbb.sql.Add( ' from( select a.bh,b.Full_Name,b.CB,b.BM,b.KB,b.XB,b.BC,b.GW,b.JN,a.rq,a.bc as jh,a.sj from RES_HR_XGRB a ');
        qry_xgbb.sql.Add( ' left join Res_Hrd_Temp b on a.bh=b.Account_Id where a.rq='''+ FormatDateTime('yyyy/mm/dd',cxDateEdit1.Date)+''' ) c order by c.rq,c.sj ');
        qry_xgbb.Open;
      end;
      

  7.   

    DBDateTimeEditEh1.value 的类型 是 variant的