刚学DELPHI,请大家帮我看看底下语句有什么错?
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add ('select * from 表 where 字段="'+Edit1.text+'"');
ADOQuery1.Active:=true;
运行上面的代码老是出错?

解决方案 »

  1.   

    不要用双引号,
    要用单引号。SQL.Add ('select * from 表 where 字段='''+Edit1.text+'''');
      

  2.   

    sql.text:='select * from 表 where 字段='+quotedstr(edit1.text);
      

  3.   

    数值型字段直接写 select * from table where id = 1  // id : Int
      

  4.   

    sql.text:='select * from 表 where 字段='+inttostr(1);
      

  5.   

    inttostr(1)这个是把数字变为字符吧?
    我的字段是数字型的,现在想把文本框的内容拿来比较,应怎么写?
      

  6.   

    楼上的怎么这么不理解 .select * from table where id = 1
    这是你最终要执行的语句。
    但在delphi里要
    sql.text:='select * from 表 where 字段='+trim(edit1.text); 
    这么写.
      

  7.   

    SQL.Add ('select * from 表 where 字段='+''''+Edit1.text+'''');
      

  8.   

    对不起,刚才没看清是数字型的,
    应该是
    SQL.Add ('select * from 表 where 字段='+Edit1.text);