这是一个实现模糊查询的程序, 有的代码看不懂, 琢磨了很长时间,还是不知道,所以只能到网上来麻烦大家了, 谢谢了啊!!!
procedure TForm1.Button1Click(Sender: TObject);
begin
datasource1.DataSet :=adoquery1;
adoquery1.Connection:=adoconnection1;
Adoquery1.close;
Adoquery1.Sql.clear;
Adoquery1.Sql.Add('select * from 商品信息表 where '+chaxun+' like :ycy');  // 什么意思?就是那个'+chaxun+' 还有like:ycy?
Adoquery1.Parameters.ParamByName('ycy').value:='%'+Trim(edit1.text)+'%';// 这个好象是模糊查询的条件 ...
Adoquery1.Prepared ;    // 这个??
Adoquery1.open;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
adotable1.Active :=true;
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
if combobox1.itemindex=0 then begin
   chaxun:='商品名称'; // ?????
   end;
if combobox1.itemindex=1 then begin
   chaxun:='商品类别';
   edit1.setfocus; end;
if combobox1.itemindex=2 then begin
   chaxun:='规格';
   edit1.SetFocus; end;
end;
end.再次不胜感激!!!!

解决方案 »

  1.   

    白写了,没提交上来,重来
    Adoquery1.Sql.Add('select * from 商品信息表 where '+chaxun+' like :ycy'); 
    chaxun 这个变量是一个动态的字段名,下面这段就是给他赋值,作者想把查询做的灵活些
    if combobox1.itemindex=0 then begin
      chaxun:='商品名称'; // ?????
      end;
    if combobox1.itemindex=1 then begin
      chaxun:='商品类别';
      edit1.setfocus; end;
    if combobox1.itemindex=2 then begin
      chaxun:='规格';  还有like:ycy  这是利用绑定参数的方式进行查询
    下面这是给参数赋值
    Adoquery1.Parameters.ParamByName('ycy').value:='%'+Trim(edit1.text)+'%'
      

  2.   

    Adoquery1.Prepared ;  这个从字面的意思也能理解吧
      

  3.   

     谢谢! 
     不过那个chaxun 还是不懂.. 做什么用的, 要预先定义吗?   哎,感觉自己太.....
      

  4.   

    3楼的野狼同志说的很清楚了,chaxun 是一个SQL的一个字段名。建议楼主瞅瞅SQL的HELP。