下面这段简单的程序是想将recordset中记录的数目统计出来,显示在text中,但为什么在rs.movelast这行中出现“行集不支持反向取呢”??
Dim cn As ADODB.Connection
Dim strCN As String
Set cn = New Connection
strCN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\WINDOWS\Desktop\db2.mdb;Persist Security Info=False"
cn.Open strCN
Dim cmd As ADODB.Command
Set cmd = New Command
Dim rs As New ADODB.Recordset
Set cmd.ActiveConnection = cn
cmd.CommandText = "select*from 123"
Set rs = cmd.Execute
    
rs.MoveFirst
     rs.MoveLast
    Text1.Text = rs.RecordCount

解决方案 »

  1.   

    adoCmm.ActiveConnection = adoCnn
     adoCmm.CommandType = adCmdText
     adoCmm.CommandText = "select * from employees"
     Set Rs = adoCmm.Execute
    看一下Rs.RecordCount 有多少条?
      

  2.   

    CN.CursorLocation = adUseClient   为客户端游标cn.Open strCN
      

  3.   

    adoCmm.ActiveConnection = adoCnn
    adoCmm.CursorLocation = adUserClient
     adoCmm.CommandType = adCmdText
     adoCmm.CommandText = "select * from employees"
     Set Rs = adoCmm.Execute
      

  4.   

    Dim rs As New ADODB.Recordset,得到的rs记录集对象默认为OpenKeyForward游标型,不支持反向访问记录。
      

  5.   

    Dim adoCnn As New ADODB.Connection
     Dim adoCmm As New ADODB.Command Dim adoRec As New ADODB.Recordset adoCnn.CursorLocation = adUseClient
     adoCnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB;Persist Security Info=False" adoCmm.ActiveConnection = adoCnn
     adoCmm.CommandType = adCmdText
     adoCmm.CommandText = "select * from employees"
     Set adoRec = adoCmm.Execute adoRec.MoveFirst Set DataGrid1.DataSource = adoRec行的,没问题的