分享

多個CheckBox製作SQL的WHERE組合

 悟静 2009-07-16
多個CheckBox製作SQL的WHERE組合
●拉三個CheckBox、三個TextBox與一個CommandButton。
●簡單的CheckBox與SQL的WHERE子句處理方式:
Private Sub Check1_Click()
Dim strSQL As String
Dim IsFirst As Boolean
IsFirst = True
strSQL = "SELECT * FROM MyTable "

 

If Check1.Value = 1 Or Check2.Value = 1 Or Check3.Value = 1 Then
strSQL = strSQL & "WHERE "
End If

 

If Check1.Value = 1 Then
strSQL = strSQL & "MyName = '" & Text1.Text & "' "
IsFirst = False
End If

 

If Check2.Value = 1 Then
If IsFirst = False Then
strSQL = strSQL & "AND "
End If
strSQL = strSQL & "MyDate = '" & Text2.Text & "' "
IsFirst = False
End If

 

If Check3.Value = 1 Then
If IsFirst = False Then
strSQL = strSQL & "AND "
End If
strSQL = strSQL & "MyGender = '" & Text3.Text & "' "
IsFirst = False
End If

 

MsgBox strSQL
End Sub

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多