例如:
    我有一个姓名文本框,还有一个出生年月日文本框等条件……
    我想动态判断条件!
    如姓名文本框有值,则查询条件应为( select ……where name=txtname.text)
    下一个生日文本框有值:
             "and birdate=birdate.text"     明白了吧!怎么做判断!问题是字符串连接时,"and"如何处理!

解决方案 »

  1.   

    代碼大致如下,實現沒問題。
    Dim wherestr As String
    wherestr = ""
    wherestr = IIf(txtname.Text = "", wherestr, wherestr & " and name='" & txtname.Text & "'")
    wherestr = IIf(birdate.Text = "", wherestr, wherestr & " and birthday='" & birdate.Text & "'")
    If wherestr = "" Then
        MsgBox "條件不足!"
        Exit Sub
    Else
        wherestr = Right(a_wherestr, Len(a_wherestr) - 4)
        g_sql = "select .... where " & wherestr & ""
        ......
        ...... 
        
    End If