Private Sub Command1_Click()
Dim pStatus As String
Dim a As String
a = Trim(Text1.Text)
Dim b As String
b = Trim(Text2.Text)
Dim c  As String
c = Trim(Text3.Text)
Dim padoConnection As New ADODB.Connection
With padoConnection
        .ConnectionString = "provider=microsoft.jet.oledb.4.0;persist security info=false;data source=" & App.Path & "\物品领用登记表.mdb"
        .Open
    If .State = adStateOpen Then
        pStatus = "Connection is OK!"
    Else
        pStatus = "Connection is Failed!"
    End If
End With
With Adodc1
    .ConnectionString = padoConnection
    .RecordSource = "select * from 物品领用登记表 where 领用人姓名 LIKE '%" + a + "%' and 物品名称 LIKE '%" + b + "%' and 数量 like '%" + c + "%'" + " and 领用日期 between '" + Text4.Text + "' and '" + Text5.Text + "'"
    .LockType = adLockOptimistic
End With
Adodc1.Refresh
DoEvents
DataGrid1.Refresh
Set DataGrid1.DataSource = Adodc1
End Sub
这个RecordSource = "select * from 物品领用登记表 where 领用人姓名 LIKE '%" + a + "%' and 物品名称 LIKE '%" + b + "%' and 数量 like '%" + c + "%'" + " and 领用日期 between '" + Text4.Text + "' and '" + Text5.Text + "
并没有错,显示所有记录,但是根据条件查询,没有任何变化请问哪里出了错。

解决方案 »

  1.   

    沒有錯吧,是數據全部符合以上where后面的全部條件,打開數據庫看一看
      

  2.   

    估计数据用的不对吧
    用了like,可能用的都能查到所有记录吧
      

  3.   

    绝对是select语句条件的问题,如果符合条件的数据是存在的话,那么肯定能找出来,建议
    设定一个temp=select...语句,运行看看你的语句是否正确!
      

  4.   

    物品领用登记表是ACCESS数据库,SELECT语句并没有问题。我做了个查询的小程序,采用的模糊查询方式,就是这种RecordSource = "select * from 物品领用登记表 where 领用人姓名 LIKE '%" + a + "%' and 物品名称 LIKE '%" + b + "%' and 数量 like '%" + c + "%'" + " and 领用日期 between '" + Text4.Text + "' and '" + Text5.Text + "'"
    语句。这个却显示全部,不能根据条件来查询。这个语句是万能查询,输入为空表示全部,逐个条件输入也可以。该怎么解决,请大家帮忙啊!在线等待,谢谢大虾
      

  5.   

    ACCESS like 可能不用 %  ,用  * 试试看。
    如: LIKE '*" + a + "*'
      

  6.   

    楼主的意思是组合查询语句吧,给你一个思路:    Dim Sql As String
        Dim sql1,sql2,sql3,sql4 
        Dim a, b, c    Sql = "select * from 物品领用登记表 where 1 = 1 "
        If a <>"" Then sql1 = "and 领用人姓名 like '%"& a &"%' " Else sql1=""
        If b <>"" Then sql2 = "and 物品名称 like '%"& b &"%' " Else sql2=""
        ......
        Sql = Sql & sql1 & sql2 & sql3 & sql4 
        Adodc1.RecordSource=SQL注意语句之间要有空格
      

  7.   

    Adodc1.Recordset.Requery
    Set DataGrid1.DataSource = Adodc1