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'大'。
请问,那为高手知道原因啊? 

解决方案 »

  1.   

    if edit18.Text<>'' then 
       asq:=asq+'and 项目名称 LIKE %'''+edit18.text+'''%';
    这是错了,改成:if edit18.Text<>'' then 
       asq:=asq+'and 项目名称 LIKE ''%'+edit18.text+'%''';
      

  2.   

    asq:=asq+'and 项目名称 LIKE %'''+edit18.text+'''%';
    将其改为
    asq:=asq+'and 项目名称 LIKE '%''+edit18.text+''%'';
      

  3.   

    var asq:string;
    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; 
      

  4.   

    碰到过一样的问题,不过当通不过的时候,最好用个label.caption:=asq;
    来显示一下语句,那就一幕了然了,或者显示出来的拿到sqlserver中调试一下,那就更清楚了:)—————————————————————————————————
    笨鸟未飞