473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Returning recordsets from a stored procedure

(IIS 6.0, SQL Server 2000)

I have a block of code that populates a recordset from a stored procedure.
The problem is, the recordset seems to be forward only (which would be OK),
but can't jump with the "AbsolutePage" property (which isn't OK)

How do I define the recordset that will allow this?

Julian
----------------------------------------------------------------------------------
Set adocmd = Server.CreateObject("ADODB.Command")
adocmd.CommandTimeout = 120
adocmd.ActiveConnection = conn
adocmd.CommandType = adCmdStoredProc
adocmd.CommandText = "dbo.spr_searchALL"

Set rsSearchM = Server.CreateObject ("ADODB.Recordset")
rsSearchM.ActiveConnection = conn
rsSearchM.CursorLocation = 3

' write to database using spr
With adocmd

set param = .CreateParameter("@criteria", adVarchar, adParamInput, 50,
"red" )
.parameters.append param

set param = .createparameter("@numrows", adInteger, adParamOutput)
.parameters.append param

On Error Resume Next

errorstring = ""
errornumber = 0
valid = 0

rsSearchM.open = .execute

'-- check the return value
If Err.Number <0 Then
errorstring = "<p>Error Number " & Err.Number & "<br>" & "The Error
Code was: " & Err.Description & "</p>"
errornumber = Err.Number
Response.Write(errorstring)
Response.Redirect(HomePath & "/error.asp?eid=unknown")
End If

.execute
numrowsM = .Parameters("@numrows").Value

End With
On Error GoTo 0
set adocmd = nothing

pagesize = 1000
rsSearchM.PageSize = pagesize
numpages = rsSearchM.PageCount

rsSearchM.MoveFirst
rsSearchM.AbsolutePage = currpage

----------------------------------------------------------------------------------

Jul 27 '07 #1
4 17366
stjulian wrote:
(IIS 6.0, SQL Server 2000)

I have a block of code that populates a recordset from a stored
procedure. The problem is, the recordset seems to be forward only (which
would
be OK), but can't jump with the "AbsolutePage" property (which isn't OK)

How do I define the recordset that will allow this?

Julian
----------------------------------------------------------------------------------
Set adocmd = Server.CreateObject("ADODB.Command")
adocmd.CommandTimeout = 120
adocmd.ActiveConnection = conn
adocmd.CommandType = adCmdStoredProc
adocmd.CommandText = "dbo.spr_searchALL"

Set rsSearchM = Server.CreateObject ("ADODB.Recordset")
rsSearchM.ActiveConnection = conn
rsSearchM.CursorLocation = 3
I'm assuming that's adUseClient (too lazy to look it up). Why not use the
constant instead of the "3"?
>
' write to database using spr
With adocmd

set param = .CreateParameter("@criteria", adVarchar, adParamInput,
50, "red" )
.parameters.append param

set param = .createparameter("@numrows", adInteger, adParamOutput)
.parameters.append param

On Error Resume Next

errorstring = ""
errornumber = 0
valid = 0

rsSearchM.open = .execute
That is very strange syntax! It really works? Anyways, the Execute method
creates a NEW recordset with default properties. I'm not sure why that Open
method is allowing the recordset returned from Execute to be assigned to
rsSearchM, but given your results, it certainly seems to be. The correct
syntax of course is:

rs.Open adocmd
>
'-- check the return value
If Err.Number <0 Then
errorstring = "<p>Error Number " & Err.Number & "<br>" & "The
Error Code was: " & Err.Description & "</p>"
errornumber = Err.Number
Response.Write(errorstring)
Response.Redirect(HomePath & "/error.asp?eid=unknown")
End If

.execute
You're executing it twice?? There is no reason to do that. The open
statement above should provide a client-side static cursor. As long as you
have a SET NOCOUNT STATEMENT in your stored procedure, and the procedure
only returns a single recordset, you should be able to read the output
parameter at this point without calliing .Execute again.
numrowsM = .Parameters("@numrows").Value
Curious. I would not have expected you to be able to get the parameter
value at this point without consuming the recordset returned by the
procedure. You've confirmed that you are actually getting a value at this
point?


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 27 '07 #2
stjulian wrote:
(IIS 6.0, SQL Server 2000)

I have a block of code that populates a recordset from a stored
procedure. The problem is, the recordset seems to be forward only (which
would
be OK), but can't jump with the "AbsolutePage" property (which isn't OK)
PS. You should investigate more efficient methods to accomplish
record-paging. Here are a couple examples:
http://databases.aspfaq.com/database...recordset.html
http://www.adopenstatic.com/experime...dsetpaging.asp
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 27 '07 #3
Yup.

I do a lot of copying and pasting from my old code. Just got used to the 3 I
guess.

I have even done a simple

SET rsSearchM = .execute

That doesn't give the desired results either.

There is a SET NOCOUNT ON statement before the SELECT that makes the
recordset in the SP

The @numrows comes from

SET @numrows = @@ROWCOUNT

and the value is not returned without the second ".execute" stement.

Any other ideas?

This should be easier for me. But, thank You for all the help.

Julian


"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:eO**************@TK2MSFTNGP06.phx.gbl...
stjulian wrote:
>(IIS 6.0, SQL Server 2000)

I have a block of code that populates a recordset from a stored
procedure. The problem is, the recordset seems to be forward only (which
would
be OK), but can't jump with the "AbsolutePage" property (which isn't OK)

How do I define the recordset that will allow this?

Julian
----------------------------------------------------------------------------------
Set adocmd = Server.CreateObject("ADODB.Command")
adocmd.CommandTimeout = 120
adocmd.ActiveConnection = conn
adocmd.CommandType = adCmdStoredProc
adocmd.CommandText = "dbo.spr_searchALL"

Set rsSearchM = Server.CreateObject ("ADODB.Recordset")
rsSearchM.ActiveConnection = conn
rsSearchM.CursorLocation = 3

I'm assuming that's adUseClient (too lazy to look it up). Why not use the
constant instead of the "3"?
>>
' write to database using spr
With adocmd

set param = .CreateParameter("@criteria", adVarchar, adParamInput,
50, "red" )
.parameters.append param

set param = .createparameter("@numrows", adInteger, adParamOutput)
.parameters.append param

On Error Resume Next

errorstring = ""
errornumber = 0
valid = 0

rsSearchM.open = .execute

That is very strange syntax! It really works? Anyways, the Execute method
creates a NEW recordset with default properties. I'm not sure why that
Open method is allowing the recordset returned from Execute to be assigned
to rsSearchM, but given your results, it certainly seems to be. The
correct syntax of course is:

rs.Open adocmd
>>
'-- check the return value
If Err.Number <0 Then
errorstring = "<p>Error Number " & Err.Number & "<br>" & "The
Error Code was: " & Err.Description & "</p>"
errornumber = Err.Number
Response.Write(errorstring)
Response.Redirect(HomePath & "/error.asp?eid=unknown")
End If

.execute

You're executing it twice?? There is no reason to do that. The open
statement above should provide a client-side static cursor. As long as you
have a SET NOCOUNT STATEMENT in your stored procedure, and the procedure
only returns a single recordset, you should be able to read the output
parameter at this point without calliing .Execute again.
> numrowsM = .Parameters("@numrows").Value
Curious. I would not have expected you to be able to get the parameter
value at this point without consuming the recordset returned by the
procedure. You've confirmed that you are actually getting a value at this
point?


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Jul 27 '07 #4
stjulian wrote:
Yup.

I do a lot of copying and pasting from my old code. Just got used to
the 3 I guess.

I have even done a simple

SET rsSearchM = .execute

That doesn't give the desired results either.
It shouldn't. Did you read my initial reply carefully? Execute always
returns a server-side forwardonly recordset (unless you have earlier
modified the cursorlocation property of the Connection object to make
adUseClient the default cursor location)

SQL Server will not return the output parameter value until all recordsets
returned by the procedure have been consumed. With a server-side cursor,
that means you need to move to the last record in the recordset, or close
it, before attempting to read the output parameter value. With a client-side
cursor, the entire resultset is sent to the client (ADO) and put into a
client-side cursor, so the output parameter value should be available
immediately after the recordset.open statement.
>
There is a SET NOCOUNT ON statement before the SELECT that makes the
recordset in the SP
Actually, SET NOCOUNT ON should be the first statement in the procedure, but
it shouldn't matter where it is in the procedure.
>
The @numrows comes from

SET @numrows = @@ROWCOUNT

and the value is not returned without the second ".execute" stement.
I'm amazed that it is returned. When you execute the procedure again, it
does all the actions that it performed the first time, including sending the
resultset again. Hmm, perhaps ADO consumes those results when you don't
assign them to a recordset variable ...
>
Any other ideas?
I'm still unclear as to what I am trying to fix. Did you revise your code
per my initial reply? Specifically, eliminate both Execute statements and
use

rs.Open adocmd

If so, show me your new code as well as the text of the stored procedure.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 27 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Eli Sidwell | last post by:
Trying to return a Recordset to an ASP and the Recordset is empty. The StorredProc works in the query analyzer and it even works from a quick VB app that I wrote to test it. The storedproc that...
4
by: Michael Trosen | last post by:
Hi Everyone, I hope someone can help, I'm pretty new to pro*c programming. I have the following application setup: a pro*c program calls a stored procedure and recieves a cursor back: the...
7
by: (Pete Cresswell) | last post by:
I posted this in the MS Access group, but no luck. ------------------------------------------ I've got another stored procedure in the same app that returns multiple recordsets and the code works....
5
by: rhungund | last post by:
Hi All. My question is this. I have a complex stored procedure in SQL Server which works fine when I run it in Query Analyzer. However, when I call it within my ASP script, it returns nothing,...
16
by: Randy Harris | last post by:
I was inspired by the recent discussion of returning multiple recordsets to ADO from a stored procedure. (Amazed is probably more accurate). I asked about how to accomplish same with Oracle and...
4
by: scparker | last post by:
Hello, We have a stored procedure that does a basic insert of values. I am then able to retrieve the ID number created for this new record. We are currently using ASP.NET 2.0 and use N-Tier...
1
by: stjulian | last post by:
I have a stored procedure which returns 2 tables and 1 output value. I want the first table to be assigned to rs1 and the second to rs2. However when I run this, I get the following error as I...
3
by: Homer J. Simpson | last post by:
I have the following stored procedure: ALTER PROCEDURE . AS BEGIN SET NOCOUNT ON; SELECT COUNT(*) FROM QUICKNOTES END ....and the following data source in my .aspx file:
3
by: Dooza | last post by:
Hi there, I have a Stored Procedure in SQL 2000 that takes 10 input paremeters, and outputs 11 recordsets, not rows, but 11 different SELECT statements. The purpose of this is to for a menu...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.