不如前面加checkbox来判断是否该字段和关键字组合是否生效生成几个变量或用数组如果 为true 就根据 字段值和关键字生成 查询语句然后查询时加上变量即可
参考一下

解决方案 »

  1.   

    checkbox和if来判断是否该字段作为条件,先生成SQL语句
      

  2.   

    如果字段不是很多的话,可以采用上面几位的方法,用checkbox配合edti文本框实现。当然字段过多的时候就有问题了,毕竟你的页面上也防不下那么多。可以让用户首先从字段列表中选择字段,然后让唯一的文本框可用并允许输入值,最后用一个按钮添加语句到sql中。操作分3步走,就看用户是否觉得烦了
      

  3.   

    http://delphi.mychangshu.com/dispdoc.asp?id=861
      

  4.   


    [email protected]下面代码也实现所要求的功能,但一大片的if语句看起来真不爽。
    如果 tangyong_delphi() 有好方法请发到信箱,多谢 ,呵呵
    procedure TmultiQueryForm.BitBtn1Click(Sender: TObject);
    var
      recordnum:integer;
      strSql:string;
    begin
    recordnum:=0;strSql:='select * from info where true';strSql:=strSql+sqlcon; //调用sqlcon方法
    //////
    adoquery1.Close;
    adoquery1.SQL.Clear;
    adoquery1.SQL.Add (strSql);
    try
      adoquery1.Open;
      if not adoquery1.IsEmpty then
         begin
           recordnum:=adoquery1.RecordCount;
           StatusBar1.Panels[0].Text :=' 共查询到   '+inttostr(recordnum)+'   条符合条件的记录!';
         end
      else
           showmessage('  对不起,没有查找到符合条件的记录!  ');
    except
      showmessage('查询出现错误,xxxxxxxxxxxxxx');
    end;end;
    //////////////
    function TmultiQueryForm.sqlcon: string;
    var
      strSql:string;
    begin
    strSql:='';
    if editIsnull(trim(edit1.text)) then
       strSql:=strSql+' and 姓名='+'"'+trim(edit1.text)+'"';
    if editIsnull(trim(edit2.text)) then
       strSql:=strSql+' and 用户号码='+'"'+trim(edit2.text)+'"';
    if editIsnull(trim(edit3.text)) then
       strSql:=strSql+' and 地址码='+'"'+trim(edit3.text)+'"';
    if checkbox1.Checked then
       strSql:=strSql+' and 启用日期 between '+'#'+datetostr(d1.date)+'#'+' and '+'#'+datetostr(d11.date)+'#';
    if checkbox2.Checked then
       strSql:=strSql+' and 结束日期 between '+'#'+datetostr(d2.date)+'#'+' and '+'#'+datetostr(d22.date)+'#';
    if editIsnull(trim(combobox1.text)) then
       strSql:=strSql+' and 入网方式='+'"'+trim(combobox1.text)+'"';
    if editIsnull(trim(edit4.text)) then
       strSql:=strSql+' and 机型='+'"'+trim(edit4.text)+'"';
    if editIsnull(trim(combobox2.text)) then
       strSql:=strSql+' and 类别='+trim(combobox2.text);
    if editIsnull(trim(combobox3.text)) then
       strSql:=strSql+' and 部门='+'"'+trim(combobox3.text)+'"';result:=strSql;end;