做了个表单查询,用了很多的CHECK,查询数据库时如何结合CHECK来查询,有选有不选的情况下,用的是ADO连接,该怎么来做查询语句,最好提供点代码,谢谢
解决方案 »
- VB编程把Spreadsheet控件中的数据导出到.xls中
- 用setupfactory打包,为何设定快捷方式在所有程序上显示,但却同时显示在开始菜单上面,如何只在所有程序后面显示呢?
- 如何删去字符串中的空格?
- 个人感觉VB运行出错时给出的错误提示不是很详细,有没有办法取得较为详细的错误信息
- 请教您啦: 编程访问远程文件
- 简单问题
- 哪位大哥请告诉我vfp6.0数据库支持触发器和存储过程吗?谢谢
- 关于VB 下面代码的一点疑惑?(菜鸟求知)
- 随机数高难度问题!
- 请大神看看这个小问题
- 关于setwindowpos函数的。。。。。
- 我不想说我是鸡!!! :( :( : (:( :(:( :( :( :(
Dim strSql As String, i As Integer
strSql = "select "
For i = 0 To Check.Count - 1
If Check(i).Value = 1 Then
strSql = strSql & Check(i).Tag & ","
End If
Next
strSql = Left(strSql, Len(strSql) - 1) & " from tableName"
End Sub
Check(1).Tag=Table1.Col2Check(2).Tag=Table2.Col1
Check(3).Tag=Table3.Col2Check(4).Tag=Table3.Col3
Check(5).Tag=Table3.Col4......
不过,你事先设置好Tag属性,就想上面说的一样,如果用户选择Check(0),表示需要查询Table1的Col1列,如果选择Check(3),表示需要查询Table2的Col2列
Dim i%, strCondition As String, strSql As String, arrTmp() As String, strTable As String
For i = 0 To Check1.Count - 1
If Check1(i).Value = 1 Then
'取得查询条件====================
If Trim(strCondition) <> "" Then
strCondition = strCondition & " and " & Check1(i).Tag & "=" & Text1(i).Text
Else
strCondition = Check1(i).Tag & "=" & Text1(i).Text
End If
'===============================
'取得要查询的表==================
arrTmp = Split(Check1(i).Tag, ".")
If InStr(strTable, arrTmp(0)) = 0 Then
strTable = strTable & "," & arrTmp(0)
End If
'===============================
End If
Next
strTable = Mid(Trim(strTable), 2) '去掉第一个逗号
strSql = "select * from " & strTable & " where " & strCondition
Debug.Print strSql
End Sub