sramkris
asked on
Ado Recordset and Record Count Urgent !!!!
Hi
I am trying to execute a stored procedure with one parameter.If i use the recordset.open 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=raje sh"
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 recordset.open method gives the record count as -1
I really need this quite urgently
Any help will be really appreciated
Thanks
I am trying to execute a stored procedure with one parameter.If i use the recordset.open 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=raje
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 recordset.open method gives the record count as -1
I really need this quite urgently
Any help will be really appreciated
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Change your CursorType -or- execute a separate SELECT COUNT SQL statement to get what you want.. <smile>.
ASKER
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 .Connectio n")
strConnstring = "DSN=Bull;UID=ram;PWD=raje sh"
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,adLoc kBatchOpti mistic
gives the same error.If the cursor type is adopenkeyset or adopendynamic the result is the same
Set oConn = Server.CreateObject("ADODB
strConnstring = "DSN=Bull;UID=ram;PWD=raje
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,adLoc
gives the same error.If the cursor type is adopenkeyset or adopendynamic the result is the same
rsIni.Open "ccc_statementofwork " & 134325,,adOpenKeyset,adLoc kBatchOpti mistic
"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>.
"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.
Remarks
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.
Remarks
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.
--------------------------
Parameters Collection
Contains all the Parameter objects of a Command object.
Remarks
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.
Remarks
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.
Dear sramkris, i think you were so close to your solution:
replace
Set recBull = oComm.Execute()
by
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
replace
Set recBull = oComm.Execute()
by
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
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
recBull.CursorType=adOpenK
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.
ASKER
Thanks a lot guys for helping me out.This was a lot of information i received.
Ram
Ram