Link to home
Start Free TrialLog in
Avatar of gdlp2004
gdlp2004

asked on

Saving Resultset to Session or Request Scope

With the following code, and where I put my comment, I want to save this resultset to a request scope (or session).  How do you do both, and how do you pull it out and iterate through it when you want to retrieve it on another page?  I know in Java it is request.setAttribute("SOMETHING",somethingsValue); but I don't know it in ASP.

Here is my code:

Set Con = Server.CreateObject( "ADODB.Connection" )
Con.Open strConn


DIM questionSQL, questionRs

questionSQL = "SELECT quizid, difficultytype, maxnumberofquestions from quiz"
SET questionRs = con.execute(questionSQL)
' I want to save to request scope here
questionRs.close %>

</body>
</html>
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Generally speaking, it is best not to store a result set to a session variable as it is a complete resource hog.

If you really, really, want to do that, however, you can do something like this:

SET questionRs = con.execute(questionSQL)
arrResultSet = questionRs.GetRows()
Session("ResultSet") = arrResultSet


FtB
Avatar of gdlp2004
gdlp2004

ASKER

How about as a request variable?
Would it be Request("ResultSetName") = arrResultSet?

And then, to iterate through it do you do:

while Request("ResultSetName").EOF?  Or do you have to save it as another variable then iterate?
Saving a request variable is much better :

Session("strRequestVariable") = Request.Form("strNameOfVariableYouWantToSave")

and then to retrieve the variable:

Response.write(Session("strRequestVariable"))

FtB
Cool.  Now that I know how to use both, can you do it without using Session at all?  I mean, just save a variable to the Request object and then pull it out?

Also, say if this recordset has 5 records that I want to display, how do you iterate through it when you pull it from the Request?  Is it the same as the code I last posted?
ASKER CERTIFIED SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That will work.  Thanks!
Glad to have helped,

FtB