在三层结构中如果我的GGG.CommandText:=  'select * from nm where bm= '''+edit1.text+'''  ';EDIT1.TEXT中有单引号出现就会报错如何解决

解决方案 »

  1.   

    //GGG.CommandText:=  'select * from nm where bm= '''+edit1.text+'''  'GGG.CommandText :=  Format('select * from nm where bm =  %s',
      [QuotedStr(edit1.text)]);
      

  2.   

    GGG.CommandText:=  'select * from nm where bm= '+QuotedStr(StringReplace(Edit1.Text,'''','''''',[]));
      

  3.   

    GGG.CommandText:= 'select * from nm where bm= ''['+edit1.text+']'' '
      

  4.   

    GGG.CommandText:= 'select * from nm where bm= '''+edit1.text+'''';
      

  5.   

    GGG.CommandText := 'select * from nm where bm = :Param';
    GGG.Parameters.ParaByName('Param').Value := Edit1.Text;
      

  6.   

    用传递SQL语句的方法不好,,很容易出问题,,(多客户并发性)
      

  7.   

    在将DELPHI中的字符串转成SQL语句时,必须避免被转换的字符串中包含单引号,如有单引号,必须转换成双引号,这是大家在做数据库程序都应解决的问题。
    转换的方法楼上的兄弟都提到了