VB同时两个条件查询access数据

VB同时两个条件查询access数据,第1张

假设你数据库里都是储存为字符串的,SQL语句如下

"select * form 样本数据 where 车号=' " &text1.text &"' and 日期='" &combo1.text &"'"

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

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

sql = "select * from 基本信息 where 供货公司 like '%" &Trim(Text1.Text) &"%'and 车牌号 like '%" &Trim(Text2.Text) &"%' and 日期>= #" &DTPicker1.Value &"# And 日期<= #" &DTPicker2.Value &"# "

用模糊查询,如果文本框内容为空,则显示全部。


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存