要求查询:
Select * from myTable 
where myField like %什么%注意:
1、上面的“什么”是任意的
2、AdoDataset 必须是用
  Parameters.ParamByName 的方式赋值给这个参数我试过:
1、
adoDataset.commandtext:=' Select * from myTable  where myField like %:什么%';
adoDataset.Parameters.ParamByName('什么').value:='test'
系统提示找不到此参数2、
adoDataset.commandtext:=' Select * from myTable  where myField like :%什么%';
adoDataset.Parameters.ParamByName('%什么%').value:='test'
系统不出错,但找不到任何记录3、有在虾可能会说,用
 ' ... and StudentName like ''%' +  edtStudentName.Text + '%''';
的形式解决,但是一旦要查询的是单引号' 时,将会出错。
请各位帮忙解决!注意,要用Parameters.ParamByName的方法!
在线等......

解决方案 »

  1.   

    chinasdp() :
    adoDataset.commandtext:=' Select * from myTable  where myField like :fld';
    adoDataset.Parameters.ParamByName('fld').value:='%test什么%';
    如果用上面的方法,
    这样能查出记录,但是有问题:
      如果我查找的东西是
    %那么系统会把所有的东西都显示出来。
    这有点像以前有的BBS上提到的登录BUG。
      

  2.   

    ' ... and StudentName like ''%' +  edtStudentName.Text + '%''';改成这样 ' ... and StudentName like QuotedStr('%' +  edtStudentName.Text + '%');
      

  3.   

    var  s : string;
    begin
      s := 'test';
      adoDataset.Parameters.ParamByName('%什么%').value:='%'+s+'%'
    end;
    如果s为空则会查询出所有。
      

  4.   

    sql.Add('select * from myTable where myField like ''%'+Trim(edit1.Text)+'%''');