vb SQL多条件查询

vb SQL多条件查询,第1张

举例说明,实现如下多条件查询:

Private Sub Command1_Click() Dim jsql jsql = ""

Dim smyregion As String If Check1.Value = 1 Then

jsql = "图书名称 like '%" + Text1.Text + "%'" End If

If Check2.Value = 1 ThenIf jsql = "" Then

jsql = "作者姓名 like'%" + Text2.Text + "%'"Else

jsql = jsql &"and 作者姓名 like'%" + Text2.Text + "%'" End If End If

If Check3.Value = 1 ThenIf jsql = "" Then

jsql = "出版社名称 like'%" + Text3.Text + "%'" Else

jsql = jsql &"and 出版社名称 like '%" + Text3.Text + "%'" End If End If

If Check4.Value = 1 Then If jsql = "" Then

jsql = "出版时间 like '%" + Text4.Text + "%'" Else

jsql = jsql &"and 出版时间 like '%" + Text3.Text + "%'" End If End If

If Check5.Value = 1 ThenIf jsql = "" Then

jsql = "图书类别 like '%" + Text5.Text + "%'"

Else

jsql = jsql &"and 图书类别 like '%" + Text5.Text + "%'" End If End If

If jsql = "" Then

MsgBox "请选择查询条件!", vbInformation, "图书音像管理系统" Exit Sub Else

Adodc1.RecordSource = "select * from book where " &jsql Adodc1.Refresh End If

If Adodc1.Recordset.RecordCount >0 Then Set DataGrid1.DataSource = Adodc1 End IfEnd Sub

Private Sub Command2_Click() Unload Me End Sub

Private Sub Form_Load()

Dim i As Integer

On Error GoTo err

db = "\\192.168.2.252\开発部\APP_VB6\200707_アイチ补修\01_日本资料\アイチ补修\アイチ补修.mdb"

db = "Provider=Microsoft.Jet.OLEDB.4.0Persist Security Info=FalseData Source=" &db

conn.CursorLocation = adUseClient

conn.Open db

i = 0

Set Rs = conn.OpenSchema(adSchemaTables)

If Rs.EOF = False Then

Do Until Rs.EOF

If Left(Rs!TABLE_NAME, 4) <>"MSys" Then

Combo2.AddItem Rs!TABLE_NAME, i

i = i + 1

End If

Rs.MoveNext

Loop

End If

Rs.Close: Set Rs = Nothing

Exit Sub

err:

MsgBox err.Number

Unload Me

End Sub

上面是查找所有表的代码 把循环往combox里添加数据改成查询你想要的字段就可以了!~ 记得在最上面加个 ON ERROR RESUME NEXT 因为可能会有表没有这个字段!~


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9905430.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存