我要通过10个参数查询,其中可以通过一个参数或者两个参数、三个参数....直到10个参数的任意组合来实现查询,应该怎么写?

解决方案 »

  1.   

    optional 是不是你要的?sub search(byval sName as string,optional sSex as string ,optional nAge as integer)不太明白你的意思,你说得清楚一点
      

  2.   

    我认为,应该对所有的参数进行判断.以下的只是思路。
    dim a1 as string
    dim a2 as string
     .
     .
     .
    dim a10 as string
    if a1=?? then
       '模块的调用
       jieguo a1 
    end if 
     '以下雷同
     public sub jieguo (vbval a string)
      ‘具体的语句块
     end sub
      

  3.   

    是10个条件查询,比如有2个文本控件,同过这两个文本控件的值进行查询
    可以这样:
    if text1="" then
        if text2="" then
            select * from a
        else
            select * from a where id=text2
        end if
    else
        if text2="" then
            select * from a where name=text1
        else
            select * from a where id=text2 and name=text1
        end if
    end if在有2个条件下就有4种状况,可是有10个条件,可怎么写?
      

  4.   

    sqlStr=""
    if c1<>"" then
       SqlStr=SqlStr+IIF(SqlStr="","select ……where f1='" & c1 & "'"," and f1='" & c1" & "'")
    end ifif c2<>"" then
       SqlStr=SqlStr+IIF(SqlStr="","select ……where f2='" & c2 & "'"," and f2='" & c2" & "'")
    end ifif c3<>"" then
       SqlStr=SqlStr+IIF(SqlStr="","select ……where f3='" & c3 & "'"," and f3='" & c3" & "'")
    end ifif c4<>"" then
       SqlStr=SqlStr+IIF(SqlStr="","select ……where f4='" & c4 & "'"," and f4='" & c4" & "'")
    end if ……  …… ……(c1,c2……表示参数,f1,f2……表示字段)基本上按这个思路,哦应注意参数的类型,(我上面写的都是将参数作为文本来处理)不同类型的参数,只做一下相应的修改就ok 了。
      

  5.   

    你这个贴子我已经在
    http://expert.csdn.net/Expert/topic/1653/1653028.xml?temp=.7921106
    答复过你了.
      

  6.   

    to dragon525() :
    看看我改进后的东东
      

  7.   

    sql = "select * from t where (id = " & text2 & " or " & text2 " & " = '') and (name ='" & text1 & "' or " & text1 & "= '')"
    根本不需要对text1,text2进行是否为空的判断!!!
      

  8.   

    以下可以参考一下:
    设f1,f2,f3,...,f10为表t1字段,输入条件为v1,v2,...,v10。
    select * from t1 where (f1 = :v1 or v1 = '%') and (f2 = :v2 or v2 = '%') and ... and (f10 = :v10 or v10 = '%')
      

  9.   

    TO: zippooo(Sonnenschein(他真菜!)) 
    为什么不要检测文本为空的情况?!比如有空的情况则where子句被构造成
    where FieldName=''  的形式, 这能够正确地查询出值来吗?