2013-12-19 94 views

回答

2

你试图移动到最后的计数

检查
recset.MoveLast 

之前也看到,如果这有助于

RecordCount属性将返回-1只进游标; 静态或键集游标的实际计数;以及动态游标的实际计数-1或 ,具体取决于数据源。

检查这个问题:

VB6 ADODB.Recordset RecordCount property always returns -1

+0

您仍然需要回到起点,虽然否则你不能就能够读取数据。 – Andrew

+0

我尝试使用recset.MoveLast,但随后出现一个错误提示:“Rowset不支持向后提取” – Kentot

1

你能尝试添加此:

objRS.CursorLocation = adUseClient 
objRS.Open strSQL, objConn,,adLockReadOnly, adCmdText 

光标位置是非常重要的。

希望这有助于..

1

如果我没有记错的记录计数不填充直到您移动到最后。我认为(在这里挖沙我的记忆),它是像

MyRecordSet.MoveLast 
MyRecordSet.MoveFirst 

那么你的计数应被填充

+0

这些返回错误提示“Rowset不支持向后提取”。 – Kentot

+0

这应该有所帮助 - 它因为你的记录集打开为“forwardOnly”http://stackoverflow.com/questions/14122308/rowset-does-not-support-scrolling-backward – Andrew

+0

只是不要调用MoveFirst。我猜错误正在被抛出? –

4

指定的参数是很重要的:在连接对象的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