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>
gdlp2004Asked:
Who is Participating?
 
fritz_the_blankConnect With a Mentor Commented:
I am afraid that I don't understand you. Perhaps if you tell me what you want to accomplish, I can suggest the best approach?

are you looking for something like:

strSQL= "SELECT * FROM tblYourTable WHERE ID " = Request.Form("ID")
set objRS=Server.CreateObject("ADODB.RecordSet")
objRS.Open strSQL,objConnection,3,3


Response.Write("<Table Border=1 cellpadding=2 cellspacing=2>")
for i=1 to objRS.RecordCount
      Response.Write("<TR>")
      for j=0 to objRS.Fields.count-1
            Response.Write("<TD>" & objRS(j).Value & "</TD>")
      next
      Response.Write("</TR>")
      objRS.MoveNext
next
Response.Write("</Table>")


FtB
0
 
fritz_the_blankCommented:
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
0
 
gdlp2004Author Commented:
How about as a request variable?
0
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.

 
gdlp2004Author Commented:
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?
0
 
fritz_the_blankCommented:
Saving a request variable is much better :

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

and then to retrieve the variable:

Response.write(Session("strRequestVariable"))

FtB
0
 
gdlp2004Author Commented:
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?
0
 
gdlp2004Author Commented:
That will work.  Thanks!
0
 
fritz_the_blankCommented:
Glad to have helped,

FtB
0
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.