记录集总是返回-1(excel VBA)
答
你试图移动到最后的计数
检查recset.MoveLast
之前也看到,如果这有助于
RecordCount属性将返回-1只进游标; 静态或键集游标的实际计数;以及动态游标的实际计数-1或 ,具体取决于数据源。
检查这个问题:
答
你能尝试添加此:
objRS.CursorLocation = adUseClient
objRS.Open strSQL, objConn,,adLockReadOnly, adCmdText
光标位置是非常重要的。
希望这有助于..
答
答
指定的参数是很重要的:在连接对象的CursorLocation =为adUseClient。
dbName = "DbInjectorsCatalog"
dbFilePath = "C:\DbInjectorsCatalog.mdf"
connStr = "Driver={SQL Server native Client 11.0};" & _
"Server=(LocalDB)\v11.0;" & _
"AttachDBFileName=" & dbFilePath & ";" & _
"Database=" & dbName & ";" & _
"Trusted_Connection=Yes"
sqlStr = "Select * from Injectors"
Set conn = New ADODB.Connection
conn.ConnectionString = connStr
conn.CursorLocation =为adUseClient
conn.Open
Set rs = New ADODB.Recordset
rs.Open sqlStr, connStr, adOpenStatic, adLockBatchOptimistic
全部工作的例子是在这里: http://straightitsolutions.blogspot.com/2014/12/read-recordcount-from-adodbrecordset.html
您仍然需要回到起点,虽然否则你不能就能够读取数据。 – Andrew
我尝试使用recset.MoveLast,但随后出现一个错误提示:“Rowset不支持向后提取” – Kentot