sqlstr:='where a='''+edit1.text+''' ';

解决方案 »

  1.   

    sqlstr:='where a='''+edit1.text + '''';
      

  2.   

    SQL SERVER7.0好像不认双引号
      

  3.   

    sqlstr:='where a='+''''+edit1.text + '''';
      

  4.   

    ======Try it======
    query1.close;
    query1.sql.clear;
    query1.sql.add('select * from aaa where a=:a');
    query1.parambyname('a').asstring:=edit1.text;
    query1.open;
      

  5.   

    iamycfwsy、xunji、snakeguo和mudeen的方法都正确的注:
      1、sqlstr:='where a='''+edit1.text + ''''; 中Edit1.Text最好使用Trim()函数将两边的空格去掉,否则可能会引起麻烦
      2、Delphi中两个单引号在字符串中表示一个引号
      

  6.   

    可以用QuotedStr(edit1.text)(函数大概如此,Quote不会错)
    楼上说的加引号的方法也行,不过稍微有些麻烦。
      

  7.   

    如果Edit1.text 包含单引号则必定出错
      如Edit1.text 值为 John's
      

  8.   

    sqlstr:='where a=' + QuotedStr(edit1.text);//用QuotedStr()比较安全
      

  9.   

    { 如果用 }
    sqlstr:='where a=''' + edit1.text + ''''; 
    { 当edit1.text有单引号时就会出错! }
    { 所以用QuotedStr()比较安全 }
      

  10.   

    SQL.Add(format('select * from aaa where a=''%s'' ',[edit1.text]));