RecordCount属性不起作用

这是我的代码:

Dim conServer As ADODB.Connection Dim rstResult As ADODB.Recordset Dim strSQL As String Set conServer = New ADODB.Connection conServer.ConnectionString = "PROVIDER=SQLOLEDB; " _ & "DATA SOURCE=192.168.0.204; " _ & "INITIAL CATALOG=REPORTDB2; " _ & "User ID=sa;" _ & "Password=" conServer.Open Set rstResult = New ADODB.Recordset strSQL = "set nocount on; " strSQL = strSQL & "select * from Table1;" rstResult.ActiveConnection = conServer rstResult.Open strSQL MsgBox rstResult.RecordCount, , rstResult.Fields(1).Value With rstResult .MoveFirst Do Until rstResult.EOF Debug.Print abc & "," & .Fields(0) & "," & .Fields(1).Value .MoveNext Loop End With 

MSGBOX行显示我-1作为一个RecordCount,但同时rstResult.Fields(1).Value显示第一个logging的值。 即使我通过“做直到…循环”检查msgbox或debugging窗口中的所有logging都完美显示。 问题是它不显示或工作recordcount属性。

你不能以这种方式使用RecordCount

它只会所有logging循环之后才会给出正确的logging数,而不是循环logging之前。