这样写
sqlstr='select * from table where id='+''''+str1+''''sqlstr=select * from table where id=''abc'''

sqlstr=select * from table where id='+''''+'abc'+''''

解决方案 »

  1.   

    可以用函数QuoteStr();查一下帮助,记不清了。
      

  2.   

    用Format最简单明了
    var
      ID: string;
      Year: Integer;
    begin
      S := Format('SELECT * FROM table where Year=%d AND id=''%s''', [Year, ID]);
      ShowMessage(S);
    end;
      

  3.   

    用'''',或者用Quotedstr()函数更方便
      

  4.   

    实在告不定你就单独  +chr(39)
    Sqltext:='select * from table1 where str = '+chr(39)+Edit1.Text+chr(39);
      

  5.   

    在Delphi中如果要在字符串中加入',可以在'前再加一个'
      

  6.   

    正确的写法:
    sqlstr:='select * from table where id='''+'abc'+'''';
    query1.sql.add(sqlstr);