question

suraj avatar image
suraj asked

record count

i am opening the rs like this Dim rstemp As New ADODB.Recordset rstemp.Open " Some query ", con, adOpenDynamic, adLockOptimistic If rstemp.EOF = False Then lngAfterInsertCnt = rstemp.RecordCount End If rstemp.Close rstemp.RecordCount is giving -1. WHAT COULD BE THE PROBLEM ?
tsql
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Pavel Pawlowski avatar image
Pavel Pawlowski answered
Hi, here is descrption and resolution of the problem in the KB article on MSDN: [PRB: ADO: Recordcount May Return -1][1]. It states: > When you request the RecordCount for a > serverside recordset, a -1 may return. > This occurs with ActiveX Data Objects > (ADO) version 2.0 or later when the > CursorType is adOpenForwardonly or > adOpenDynamic. What is exactly your situation. [1]: http://support.microsoft.com/kb/194973
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Oleg avatar image Oleg commented ·
@suraj 6 Pavel is spot on, the problem is caused by the cursor location. Sometimes it is possible to "fix" the problem by moving the cursor to last and then back to first record, so the record count is populated, but it is better to simply set the cursor location to the client instead. Just make sure that you set the cursor location **before** you open the recordset, not **after**, because setting it **after** the recordset is already open is too late.
rstemp.CursorLocation = adUseClient
rstemp.CursorType = adOpenDynamic 
rstemp.Open " Some query "
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.