举例说明,实现如下多条件查询:
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 Then If jsql = "" Then
jsql = "作者姓名 like'%" + Text2.Text + "%'" Else
jsql = jsql &"and 作者姓名 like'%" + Text2.Text + "%'" End If End If
If Check3.Value = 1 Then If 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 Then If 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 If End Sub
Private Sub Command2_Click() Unload Me End Sub
单项查询只需对某个字段(如卡号字段)遍历数据库,满足条件将会被列出。至于你需要显示输出数据库存中哪些字字段,可以是所有项,也可是你选择枚举出来的特定项。如获需要多项均满足条件,用and 连接多项条件查询条件。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)