Private Function userSql(aCategorySql As String, bCountrySql As String, cGenreSql As String) As String '混子@百度VB贴吧
Dim strSql As String
If aCategorySql = "所有频道" And bCountrySql = "所有国家" And cGenreSql = "所有类型" Then
userSql = "select * from webTV ORDER BY id ASC"
Else
If aCategorySql <> "所有频道" Then
strSql = " where Category='" & aCategorySql & "'"
End If
If bCountrySql <> "所有国家" Then
If strSql = "" Then
strSql = " where Country='" & bCountrySql & "'"
Else
strSql = strSql + " and Country='" & bCountrySql & "'"
End If
End If
If cGenreSql <> "所有类型" Then
If strSql = "" Then
strSql = " where Genre='" & cGenreSql & "'"
Else
strSql = strSql + " and Genre='" & cGenreSql & "'"
End If
End If
userSql = "select * from webTV" & strSql & " ORDER BY id ASC"
End If
End Function
用法:
Private Sub cboGenre_Click()
If ComboChange Then Exit Sub '迷雾航行@百度VB贴吧。不然会在窗口加载的时候直接执行click事件!
MsgBox userSql(cboCategory.Text, cboCountry.Text, cboGenre.Text)
'或调用查询函数
End Sub