首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

求教,Ado引号内字符串没正确结束

2013-11-21 
求教,Ado引号内字符串没有正确结束执行后,测试报这个错procedure TForm1.Button1Click(Sender: TObject)v

求教,Ado引号内字符串没有正确结束
执行后,测试报这个错



procedure TForm1.Button1Click(Sender: TObject);
var T:string;
begin


  if edit1.Text <> '' then
  begin
  T:=' and t.name like ''' +'%'+edit1.Text+'%'+ ''' ' ;
  end;

  if edit2.Text <> '' then
  begin
  T:= T + ' and t.about like ''' +'%'+edit2.Text+'%'+ ''' ' ;
  end;

  if edit3.Text <> '' then
  begin
  T:= T + ' and t.about1 like ''' +'%'+edit3.Text+'%'+ ''' ' ;
  end;

  with adoquery1 do
    begin
      close;
      sql.Clear;
      sql.Text:=('select t.name,t.about,t.about1 from tpl_word1 t where t.wordtype <> ''  ''' + T + '''  ') ;
      open;
    end;
end;

[解决办法]
sql.Text:=('select t.name,t.about,t.about1 from tpl_word1 t where t.wordtype <> ''  ''' + T) ;
去掉背后一个引号,见上。
[解决办法]
楼主这种写法,要是edit1,edit2,edit3中有一个引号,你就惨了。
用quotedstr('%'+edit1.text+'%')这个好用。
[解决办法]
sql.Text:=('select t.name,t.about,t.about1 from tpl_word1 t where t.wordtype <> ''  ' + T) ;
[解决办法]
T:=' and t.name like ''' +'%'+edit1.Text+'%'+ ''' ' ; 都改为:
T := ' and t.name like ''%' + Trim(Edit1.Text) + '%''';即可。其他的语句都照这个改就行了,
还有就是像2楼说的用quotedstr就可以,防止SQL 注入可以。

热点排行