我这样写
Q.close;
Q.SQL.clear;
Q.SQL.add('select 温度');
Q.SQL.add('from YczII');
Q.SQL.add('where 日期='''+theTime+'''');
Q.SQL.open;
theTime是string,形如2001-2-1 22:00:00,日期是access中的日期类型
提示类型不兼容
改成Q.SQL.add('where 日期=#StrtoDateTime(theTime)#');也不行
请问这个语句该怎么写

解决方案 »

  1.   

    today1:=formatdatetime('yyyymmdd',DateTimePicker1.datetime);
    today2:=formatdatetime('yyyymmdd',DateTimePicker2.datetime);
    str:='select * from users where 1=1 ';
    if Edit9.Text<>'' then
       str:=str+' and nick_name='''+Edit9.Text+'''';
    if Edit11.Text<>'' then
       str:=str+' and login_name='''+Edit11.Text+'''';
    if maskedit3.Text<>'' then
       str:=str+' and password='''+maskedit3.Text+'''';
    if Edit12.Text<>'' then
       str:=str+' and mobile_phone='''+Edit12.Text+'''';
    if Edit10.Text<>'' then
       str:=str+' and email='''+Edit10.Text+'''';
    if edit13.Text<>'' then
       str:=str+' and user_roles='''+edit13.Text+'''';
    if combobox7.Text<>'' then
       str:=str+' and user_level='''+combobox7.Text+'''';
    if combobox9.Text<>'' then
       str:=str+' and state='''+combobox9.Text+'''';
    if CheckBox1.Checked then
       str:=str+' and create_time>='''+today1+''' and create_time<='''+today2+'''' ;
       dm.ADOquery.SQL.Text := str;
      

  2.   

    数据库是什么?另外,用参数形式吧,绝对没有问题
    strsql:='select * from tname where tfield=:d';
    adoquery.sql.clear;
    adoquery.sql.text:=strSQL;
    adoquery.paramters.parambyname('d').value:=你的时间//这里可能打错了,不记得是什么写的了
      

  3.   

    Q.SQL.add('select 温度 from YczII where 日期=#'+theTime+'#');