Ado Recordset and Record Count Urgent !!!!

I am trying to execute a stored procedure with one parameter.If i use the method i get the record count as 11 and if i use the command object i get the record count as -1

here is the code for the command object

 Set oConn = New ADODB.Connection
strConnstring = "DSN=Bull;UID=ram;PWD=rajesh"
oConn.Open strConnstring, ram, rajesh, -1

'Create the ADO Database Connection:
Set oComm = New ADODB.Command
Set oPr = New ADODB.Parameter

Set oComm.ActiveConnection = oConn
oComm.CommandText = "ccc_statementofwork"
oComm.CommandType = adCmdStoredProc
oComm.CommandTimeout = 30000
oPr.Type = adInteger
oPr.Value = 134325
oComm.Parameters.Append oPr
Set recBull = New ADODB.Recordset
recBull.CursorLocation = adUseServer
recBull.CursorType = adOpenDynamic
recBull.LockType = adLockBatchOptimistic
Set recBull = oComm.Execute()

The same stored procedure when used in an asp page using the method gives the record count as -1

I really need this quite urgently

Any help will be really appreciated

Who is Participating?

Improve company productivity with a Business Account.Sign Up

wsh2Connect With a Mentor Commented:
recBull.CursorType = adOpenDynamic
From MSDN (Please Note the last paragraph).. <smile>:
RecordCount Property

Indicates the current number of records in a Recordset object.

Return Value:
Returns a Long value.

Use the RecordCount property to find out how many records are in a Recordset object. The property returns -1 when ADO cannot determine the number of records or if the provider or cursor type does not support RecordCount. Reading the RecordCount property on a closed Recordset causes an error.

If the Recordset object supports approximate positioning or bookmarks—that is, Supports (adApproxPosition) or Supports (adBookmark), respectively, return True—this value will be the exact number of records in the Recordset regardless of whether it has been fully populated. If the Recordset object does not support approximate positioning, this property may be a significant drain on resources because all records will have to be retrieved and counted to return an accurate RecordCount value.

The cursor type of the Recordset object affects whether the number of records can be determined. The RecordCount property will return -1 for a forward-only cursor, the actual count for a static or keyset cursor, and either -1 or the actual count, depending on the data source, for a dynamic cursor.

Change your CursorType -or- execute a separate SELECT COUNT SQL statement to get what you want.. <smile>.
sramkrisAuthor Commented:
My cursor type is adopendynamic.The problem still persist.Is it because i use Server side objects.The asp page where is have the code
Set oConn = Server.CreateObject("ADODB.Connection")
strConnstring = "DSN=Bull;UID=ram;PWD=rajesh"
oConn.Open strConnstring, ram, rajesh, -1
oConn.CommandTimeout = 30000
set rsIni = server.CreateObject ("Adodb.recordset")
      Set rsIni.ActiveConnection = oConn
        rsIni.Open "ccc_statementofwork " & 134325,,adOpenKeyset,adLockBatchOptimistic  
gives the same error.If the cursor type is adopenkeyset or adopendynamic the result is the same
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

rsIni.Open "ccc_statementofwork " & 134325,,adOpenKeyset,adLockBatchOptimistic    

"ccc_statementofwork " & 134325
Are you trying to pass a parameter here? You have to put Command Parameters into the Parameter collection to do so.. I think your -1 is because you are erroring out.. <smile>.  
From MSDN:

Parameters Collection

Contains all the Parameter objects of a Command object.


A Command object has a Parameters collection made up of Parameter objects.

Using the Refresh method on a Command object's Parameters collection retrieves provider parameter information for the stored procedure or parameterized query specified in the Command object. Some providers do not support stored procedure calls or parameterized queries; calling the Refresh method on the Parameters collection when using such a provider will return an error.

If you have not defined your own Parameter objects and you access the Parameters collection before calling the Refresh method, ADO will automatically call the method and populate the collection for you.

You can minimize calls to the provider to improve performance if you know the properties of the parameters associated with the stored procedure or parameterized query you wish to call. Use the CreateParameter method to create Parameter objects with the appropriate property settings and use the Append method to add them to the Parameters collection. This lets you set and return parameter values without having to call the provider for the parameter information. If you are writing to a provider that does not supply parameter information, you must manually populate the Parameters collection using this method to be able to use parameters at all. Use the Delete method to remove Parameter objects from the Parameters collection if necessary.

Parameter Object

A Parameter object represents a parameter or argument associated with a Command object based on a parameterized query or stored procedure.


Many providers support parameterized commands. These are commands where the desired action is defined once, but variables (or parameters) are used to alter some details of the command. For example, an SQL SELECT statement could use a parameter to define the matching criteria of a WHERE clause, and another to define the column name for a SORT BY clause.

Parameter objects represent parameters associated with parameterized queries, or the in/out arguments and the return values of stored procedures. Depending on the functionality of the provider, some collections, methods, or properties of a Parameter object may not be available.

With the collections, methods, and properties of a Parameter object, you can do the following:

Set or return the name of a parameter with the Name property.

Set or return the value of a parameter with the Value property.

Set or return parameter characteristics with the Attributes and Direction, Precision, NumericScale, Size, and Type properties.

Pass long binary or character data to a parameter with the AppendChunk method.
If you know the names and properties of the parameters associated with the stored procedure or parameterized query you wish to call, you can use the CreateParameter method to create Parameter objects with the appropriate property settings and use the Append method to add them to the Parameters collection. This lets you set and return parameter values without having to call the Refresh method on the Parameters collection to retrieve the parameter information from the provider, a potentially resource-intensive operation.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
Dear sramkris, i think you were so close to your solution:
Set recBull = oComm.Execute()
recBull.Opne oComm

Your statement erases the recordset you defined beforehand, and the command object always returns a ForwardOnly recordset (including that Recordcount will be -1 unless you did a Movelast, but then you can't go back :-(

hope this helps
You can try with

oConn.Open strConnstring, ram, 3,3


An ADO recordset is unable to provide a definite value for Recordcount when using dynamic cursors.Try Changeing your cursor type :

recBull.CursorLocation = adUseClient

Having said that, you do not always get the cursor you asked for.If you asked for certain kind of cursor combination ,which cannot be supported by your provider,ADO will give you another cursor combination that is supported by the provider without generating an error message.SO make sure you got what you asked for ,by checking the cursorType property on the Recordet after you have opened the Recordset.When you cursor get a -1 in the Recordcount that shows the cursor does not support Recordcount.SO change it to Keyset cursor instead of Dynamic cursor.This should solve you problem.Wish you Good Luck.
sramkrisAuthor Commented:
Thanks a lot guys for helping me out.This was a lot of information i received.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.