我就一个SQL查询Query1.close;
Query1.SQL.Clear;
Query1.SQL.Add('select * from bill.db where 1=1');
Query1.SQL.Add('and date='+''''+ edit1.Text +'''');
Query1.Active :=True;
Query1.open;
可运行后就报这个错!!!!
Invalid use of keyword 
Token: date='20060905'
line Number:2请高手指点
很急
在线等待

解决方案 »

  1.   

    'and 前面应留个空格为'  and
      

  2.   

    Query1.Active :=True;
    Query1.open;
    ///////
    这里随便要一句就可以了...
      

  3.   

    Add('and date='+''''+'#'+ edit1.Text +'#'+'''');如果是日期类型,要加上‘#’
      

  4.   

    上楼
    谢谢你
    本来是日期型的
    我把它转化成了字符型了
    我还是试了你的方法
    但还是报错呀
    Invalid use of keyword 
    Token: date='#20060905#'
    line Number:2
      

  5.   

    用参数传递,Delphi本来就内置了这个功能,干嘛不用的?
      

  6.   

    try
        strtodate(edit1.Text);
      except
        showmessage('输入的不是日期字段');
      end;Query1.close;
    Query1.SQL.Clear;
    Query1.SQL.Add('select * from bill.db where 1=1 ');//汪意1+1后面最好加个空格
    Query1.SQL.Add(' and date='+Quotedstr(edit1.Text));
    Query1.open;
      

  7.   

    日期型的最好用参数比较好一点,其它的都容易出错
    例如:sql语句中用date=:dd,dd为参数,然后
    self.Query1.ParamByName('dd').AsDate:=strtodate(edit1.text);
    然后open即可
      

  8.   

    Query1.SQL.Add('and date='+''''+ edit1.Text +'''');
    这一行有问题,楼主写了连续四个 ' ?如果要在字符串中表示 ' 要用 #39
      

  9.   

    Query1.close;
    Query1.SQL.Clear;
    Query1.SQL.Add('select * from bill.db where 1=1');
    Query1.SQL.Add('and date='+''''+ edit1.Text +'''');
    Query1.Active :=True;
    Query1.open;date是日期时间型,edit1.Text得到的是字符型,类型不匹配,导致这个错误的。
    应该把 edit1.Text中的内容转换为日期时间型就可以,
    具体的做法:
    你可以把edit1换成datetimepicker1日期时间控件,选择直接是日期时间型。配合你的语句就可以了。不要用edit控件。
      

  10.   

    解决了吗?错误信息的意思是“date是关键字,不能这样用”,字段名应该避免用简单的单词命名,但是如果已经改不了了,就加个Query1.SQL.Add('and [date]='+''''+ edit1.Text +'''');