vb SQL多条件查询
答案:1 悬赏:80 手机版
解决时间 2021-01-18 00:00
- 提问者网友:欺烟
- 2021-01-17 01:07
vb SQL多条件查询
最佳答案
- 五星知识达人网友:末日狂欢
- 2021-01-17 02:33
举例说明,实现如下多条件查询:
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
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
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯