有ADOQuery1 ,DBLookupComboBox1,
DBLookupComboBox1已经与数据库表a 中的日期类型字段日期绑定
现在想通过点击DBLookupComboBox1,实现按日期检索代码如下:
with  ADOQuery1 
do begin 
Close;
sql.Clear;
sql.Add('select * from a where time=:a ');
Parameters.ParamByName('a').Value:=formatdatetime('yyyy-mm-dd',strtodate(DBLookupComboBox1.text));
open;
end; 
可是编译通过,但运行时报错!
project project1.exe faised exception class econverterror with message '''is not a valid date'.process stopped.
  
  

解决方案 »

  1.   

    with  ADOQuery1 
    do begin 
    Close;
    sql.Clear;
    sql.Add('select * from a where time=:a ');
    Parameters.ParamByName('a').Value:=strtodate(DBLookupComboBox1.text);
    open;
    end;
      

  2.   

    不知道你用的什么数据库,time弄不好会是保留的关键字,用在这里不是很妥。
    Time字段如果是日期类型,完全不用转换。
    sql.Add('select * from a where time=:a ');
    Parameters.ParamByName('a').Value:=DBLookupComboBox1.ListSource.DateSet.FieldByName('你要的字段').AsDateTime;