with datamodule1.qry_bdcx do
begin
close;
sql.Clear ;
sql.Add('select * from xsbd where xsxh_id=:id '+'''%''');//报错
parambyname('id').AsString:=edit1.text;
open;
end;原意是想:select * from table where xsxh_id=id%
其中id是变量   在delphi中应该怎么写啊?????????????

解决方案 »

  1.   

    select * from xsbd where xsxh_id like '+'''+:id +'%'+'''
      

  2.   

    不对啊!!
    illegal character in input file '%'
      

  3.   

    sql.add('select * from xsbd where xsxh_id = '+'''+edit1.text+'%'+''');
    %是干甚的?
      

  4.   

    还是不对  SayForever(恒) 你的语句不能用啊!!!!!
      

  5.   

    % 表示id后面的字符不受限制
    比如说 id%
    当id=’张‘时   只要是姓张的人都被检索出来了!!!
      

  6.   

    sql.Add('select * from xsbd where xsxh_id like '+'''+:id +'%'+''');是這樣的嗎﹖
      

  7.   

    SayForever(恒) 不对啊!!
    illegal character in input file '%'
      

  8.   

    sql.add('select * from xsbd where xsxh_id like '+''''+edit1.text+'%'+'''');
      

  9.   

    sql.Add('select * from xsbd where xsxh_id like ''%:id%''');
    parambyname('id').AsString:=trim(edit1.text);
      

  10.   

    那就不要變量﹐如下﹕
    with datamodule1.qry_bdcx do
    begin
    close;
    sql.Clear ;
    sql.Add('select * from xsbd where xsxh_id like '+'''+Trim(Edit1.Text)+'%'+''');
    open;
    end;
    試一下。
      

  11.   

    with datamodule1.qry_bdcx do
    begin
    close;
    sql.Clear ;
    sql.Add('select * from xsbd where xsxh_id like :id); //这里修改
    parambyname('id').AsString:=edit1.text + '%';//这里加个%
    open;
    end;
      

  12.   

    原意是想:select * from table where xsxh_id=:id%能否改变为    select * from tabel where xsxh_id like 'id%' 
          可否满足你的要求?以下没有测试,你看行不行(请多指教)id:=edit1.text;
    with datamodule1.qry_bdcx do
    begin
    close;
    sql.Clear ;
    sql.text:='select * from xsbd where xsxh_id like '''+'id%'+'''';
    open;
    end;
      

  13.   

    那么是你在第一次写的时候(原意是想:select * from table where xsxh_id=id%
    )没说清楚——我还以为你要48%,这里你应该用like而非=
    so:
    sql.add('select * from xsbd where xsxh_id like '+''''+edit1.text+'%'+'''');
    刚才漏写几个'''',不好意思
      

  14.   

    上面wjlsmail(计算机质子)写的'id&'应该不行
      

  15.   

    人家要的是 Edit1.Text +' '+'%'
    这样一来就变成这样了select * from tabel where xsxh_id like 'id %'
    SQL.Add('select * from xsbd where xsxh_id like '+''''+edit1.text+' %'+'''');
    改成4个单引号,在delphi有时是3个,有时是4个,好好体会吧
      

  16.   

    select * from xsbd where xsxh_id like  '''+trim(Edit1.text)+''%'
    可能是这样吧。
      

  17.   

    经过测试
    lvxq(吕歌)    cailiantao(蔡练涛) 的版本能用其余的多报错为 illegal character in input file '%'谢谢