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
我是初学者,在做个报表查询时遇见这样的一个问题.
 运行提示:对象"refresh" 的方法" IAdodc"失败,请问是什么原因?该怎么改正.

解决方案 »

  1.   

    是不是查询后没有记录?
    用eof和bof判断一下,没有记录就不刷新,不然会出错
      

  2.   

    adodc控件的属性页中,RecordSource置空了没,再加一句试试:.CommandType = 8
      

  3.   

    DataGrid1.Refresh
    Set DataGrid1.DataSource = Adodc1
    这两句反过来
      

  4.   

    还可以试试:把RecordSource的那一段用另一个变量代替,如:sqlstr,变成.RecordSource=sqlstr
      

  5.   

    按这样写
    Adodc1.ConnectionString = SQLConntectString
        Adodc1.RecordSource = "Select idno,Name,defaultvalue from Charge where Idno > 2"
        Adodc1.Refresh
        Set DataGrid1.DataSource = Adodc1
      

  6.   

    去掉“DoEvents”试试。
    还有你的“物品领用登记表”是数据库还是数据表?
      

  7.   

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

  8.   

    物品领用登记表是ACCESS数据库?
                   ============
    select * from 物品领用登记表 ??
                   ============
    到底是数据库还是表?
      

  9.   

    物品领用登记表是ACCESS数据库。名称是----物品领用登记表.mdb。库中就这一个表---物品领用登记表。
      

  10.   

    ADODC好像不是代码生成的不可以使用Refresh方法