procedure TMain.Button1Click(Sender: TObject);
var
tj,tj1,tj2,tj3,tj4:string;
begin
tj1:='1=1';
if checkbox1.checked then //按计算机名查询
tj1:='name1 like'''+'%'+edit1.text+'%'+'''';tj2:='1=1';
if checkbox2.checked then //按部门名称查询
tj2:='dept like'''+'%'+edit2.text+'%'+'''';tj3:='1=1';
if checkbox3.checked then //按使用者查询
tj3:='user like'''+'%'+edit3.text+'%'+'''';tj4:='1=1';
if checkbox4.Checked then //按IP地址查询
tj4:='ip like'''+'%'+edit3.text+'%'+'''';tj:='select * from eekspcb where'
+tj1+'and'+tj2+'and'+tj3+'and'+tj4;ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(tj);ADOQuery1.Open;
end;end.运行上面的代码
为什么提示:'=' 附近有语法错误。.
http://duoken.cn/showtopic-140.aspx

解决方案 »

  1.   

    你showmessage(tj)这样输出一样看看,看看哪一句出问题了,很明显
      

  2.   

    open前,showmessage(adoquery1.sql.text)看看对不对,
    每个and,都要有空格的,a=1 and b=2 and c=3
      

  3.   

    这种拼字符串最好用 Format 和 QuotedStr 这两个函数。
      

  4.   

    ADOQuery1.Close;
    ADOQuery1.SQL.Clear;
    ADOQuery1.SQL.Add(tj);
    showmessage(tj);
    ADOQuery1.Open;
      

  5.   

    tj:='select * from eekspcb where'
    +tj1+'and'+tj2+'and'+tj3+'and'+tj4;这句有问题。如果你的tj4为空,那么后面就多了and。sql不完整了。lz你练连判断都没有。
      

  6.   

    搞定了:
    在“1=1”前加空格;computername前和like后加空格 
      

  7.   

    tj:='select * from eekspcb where'
    +tj1+'and'+tj2+'and'+tj3+'and'+tj4;里面的' and'换成' and '
      

  8.   

    你的tj1~4都是string型是吧,那再select语句中就不能'+tj1+',要写成'''+tj1+'''.你试试
      

  9.   

    错误有几个,SQL里面的关键字要左右都要有空格,还有你最后是4个’貌似不对了
      

  10.   

    tj1:=Format('name1 like %s',[QuotedStr('%'+Edit1.Text+'%')]);4楼说了。
      

  11.   

    tj:=Format('select * from eekspcb where %s and %s and %s and %s;',[tj1,tj2,tj3,tj4]);
    顺便这个也给你写了吧。
      

  12.   

    看着很吃力,养成好的Coding习惯
      

  13.   

    为什么这样拼SQL语句按你这个拼出来的语句,少了一些空格。 where 后面没有空格。。tj:='select * from eekspcb where'
    +tj1+'and'+tj2+'and'+tj3+'and'+tj4;应改成
    tj:='select * from eekspcb where '
    +tj1+' and '+tj2+' and '+tj3+' and' +tj4;再试试
      

  14.   

    应改成
    tj:='select * from eekspcb where '
    +tj1+' and '+tj2+' and '+tj3+' and ' +tj4
      

  15.   

    会跟踪吗??
    ADOQuery1.SQL.Add(tj);到这句看看  tj到底内容是什么东东,一看就知道少空格