with AdoQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from T_Custom where CustName='''+CustName+'''');
Open;
end;
这时delphi会提标有错,因为custname中有单引号,会有错误。
现在CustName这个变量中有一个'号,比如CustName:='sssssss'dseee';
我该如何做呢?用Pos能判断出一个字符串中是否存在单引号?
begin
Close;
SQL.Clear;
SQL.Add('select * from T_Custom where CustName='''+CustName+'''');
Open;
end;
这时delphi会提标有错,因为custname中有单引号,会有错误。
现在CustName这个变量中有一个'号,比如CustName:='sssssss'dseee';
我该如何做呢?用Pos能判断出一个字符串中是否存在单引号?
with AdoQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from T_Custom where CustName='+Quotedstr(CustName));
Open;
end;Quotedstr函数会自动将字符串中的单引号改为双引号的表示,并且在字符串两边加上双引号,使用很方便。
不过楼上的方法更好啊var
str:string;
begin
str:='abc''d';
str:=Quotedstr(str);
showmessage(str);
end;str此时的值是'abc''d',自动在两端加了引号!