var asq:string;
begin
if combobox1.text<>'' then
asq:='and (地区='''+combobox1.text+''')';
if edit18.Text<>'' then
asq:=asq+'and 项目名称 LIKE %'''+edit18.text+'''%';
if asq<>'' then
asq:='select * from crzdxx where 地区<>'''''+asq;
with query1 do
begin
SQL.Clear;
SQL.Add(asq);
Prepare;
try
open;
except
ExecSQL;
end;
end;
我在edit18中输入一个字符,例如“大”,运行的时候出现错误:incorrect syntax near'大'。
请问,那为高手知道原因啊?
begin
if combobox1.text<>'' then
asq:='and (地区='''+combobox1.text+''')';
if edit18.Text<>'' then
asq:=asq+'and 项目名称 LIKE %'''+edit18.text+'''%';
if asq<>'' then
asq:='select * from crzdxx where 地区<>'''''+asq;
with query1 do
begin
SQL.Clear;
SQL.Add(asq);
Prepare;
try
open;
except
ExecSQL;
end;
end;
我在edit18中输入一个字符,例如“大”,运行的时候出现错误:incorrect syntax near'大'。
请问,那为高手知道原因啊?
asq:=asq+'and 项目名称 LIKE %'''+edit18.text+'''%';
这是错了,改成:if edit18.Text<>'' then
asq:=asq+'and 项目名称 LIKE ''%'+edit18.text+'%''';
将其改为
asq:=asq+'and 项目名称 LIKE '%''+edit18.text+''%'';
begin
if Trim(combobox1.text)<>'' then
asq:='and (地区='+QuotedStr(combobox1.text)+')';
if Trim(edit18.Text)<>'' then
asq:=asq+'and 项目名称 LIKE '+QuotedStr('%'+Trim(edit18.text)+'%');
if asq<>'' then
asq:='select * from crzdxx where 地区<>'''''+asq;
with query1 do
begin
SQL.Clear;
SQL.Add(asq);
Prepare;
try
open;
except
ExecSQL;
end;
end;
来显示一下语句,那就一幕了然了,或者显示出来的拿到sqlserver中调试一下,那就更清楚了:)—————————————————————————————————
笨鸟未飞