With QryEqui do
    begin
      close ;
      Sql.Clear ;
      sql.Add('Select * from product where type=''设备''');
      sql.Add('and product_name like "%'+edit2.Text +'%"') ;
      Sql.Add('Order By Product_ID');
      Open ;
    end ;
我在 Edit2里面输入任何的东西,系统都会提示说 :列名"XXXX"无效. 这是什么问题啊。可是我把 'and product_name like "%'+edit2.Text +'%  这句子改成       sql.Add('and product_name=''edit2.Text''') ; 就没有问题,请问如何解决。谢谢

解决方案 »

  1.   

    product_name 有吗?最好是设置断点把sql考出来到数据库里执行一下。
      

  2.   

    把sql语句用showmessage显示出来看看,可能是你没有加空格
    sql.Add('Select * from product where type=''设备''');
          sql.Add(' and product_name like "%'+edit2.Text +'%"') ;
                   |
                  空格
         Sql.Add(' Order By Product_ID');
                 |
                空格
         
      

  3.   

    "%'+edit2.Text +'%"这一段应为: ''"%'+edit2.Text +'%''
      

  4.   

    改为:(QuotedStr()是一个引用函数)
    With QryEqui do
        begin
          close ;
          Sql.Clear ;
          sql.Add('Select * from product where type='+QuotedStr('设备'));
          sql.Add(' and product_name like ' + QuotedStr('%'+edit2.Text+'%')) ;
          Sql.Add(' Order By Product_ID');
          Open ;
        end ;
    另外一种可能就是Type不能作为字段名出现在SQL语句中,这可能会引起分析岐义。
      

  5.   

    改为:(QuotedStr()是一个引用函数)
    With QryEqui do
        begin
          close ;
          Sql.Clear ;
          sql.Add('Select * from product where type='+QuotedStr('设备'));
          sql.Add(' and product_name like ' + QuotedStr('%'+edit2.Text+'%')) ;
          Sql.Add(' Order By Product_ID');
          Open ;
        end ;
    另外一种可能就是Type不能作为字段名出现在SQL语句中,这可能会引起分析岐义。