想写这样的
select * from table1 where a='edit1.text'
该怎么写?

解决方案 »

  1.   

    SQLString:='select * from table1 where a='+#39+edit1.text+#39
      

  2.   

    select * from table where a = 'abc''sdjf'ADODataSet1.CommandText := 'select * from table where a = ''abc''''sdjf''';
      

  3.   

    或者:SQLString:='select * from table1 where a='''+edit1.text+''''
      

  4.   

    如果是引用:
    ADODataSet1.CommandText := 'select * from table where a = ' + QuotedStr(Edit1.Text);
      

  5.   

    用双引号代替引号:
    即‘ select * from table1 where colname=''aaa'' ’
      

  6.   

    SQLString:='select * from table1 where a='''+edit1.text+''''
      

  7.   

    在Delphi里 用''''代表一个单引号 如果有需要有一个函数也可以在字符串外加双引号
    QuotedStr()函数就是这个 ,你可以在帮助里查找到
      

  8.   

    with query1 do begin
       close;
       add.clear;
       add.sql('select * from table1 where a='''+edit1.text+'''');
       open;
    end;
      

  9.   

    select * from table1 where a='''+edit1.text+'''
      

  10.   

    你可以这样写
    var s:string;
     s:=edit1.text;
    with query1 do begin
       close;
       add.clear;
       add.sql(format('select * from table1 where a=''%s''',[s]));
       open;
    end;
    问题一定能够解决
      

  11.   

    'select * from table1 where a='''+edit1.text+'''
      

  12.   

    同意 hunterht(核桃-俺就是核桃的马甲)QuotedStr()這個函數會自動將單引號替代為兩個單引號﹐在用
    ADOQuery1.SQL.Add('select * from table1 where a='''+edit1.text'''');
    的時候加上該函數可以防止Edit1.Text中有單引號出錯甚至出現漏洞
    改為
    ADOQuery1.SQL.Add('select * from table where a='+QuotedStr(edit1.text));
    就不會出錯