|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
我想在一段程序里面同时使用两个记录集(recordset):rst 和 rst2 ,希望他们开始时同时指向一个地方,然后rst不断向后移动(rst.movenext),而rst2不移动,我的程序如下,在程序中rst2好像跟着rst移动了,应该如何改,谢谢!!:
Sub 连接进销存表数据库()
Dim conn As ADODB.Connection
Dim WN As String
Dim sSql As String
Dim TableName As String
Dim ColumnName As String
Dim i As Integer
Dim rst As ADODB.Recordset
Dim rst2 As ADODB.Recordset
WN = "3.mdb"
TableName = "SH_600000_2008"
ColumnName = "示例栏"
Set conn = New ADODB.Connection
Set rst = New ADODB.Recordset
With conn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & [CurrentProject].[Path] & "\" & WN
.Open
End With
If conn.State = 1 Then
MsgBox "连接成功!"
rst.Open Source:=TableName, ActiveConnection:=conn.ConnectionString, CursorType:=adOpenDynamic, LockType:=adLockOptimistic
If rst.State = 1 Then
MsgBox "记录集打开成功!"
End If
Set rst2 = rst
i = 0
Do While Not rst.EOF
rst.MoveNext
rst("示例栏") = i
i = i + 1
MsgBox "rst = " & rst("示例栏")
MsgBox "rst2 = " & rst2("示例栏")
Loop
rst.Close
rst2.Close
conn.Close
End If
Set conn = Nothing
End Sub |
|