[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Saving Resultset to Session or Request Scope

Posted on 2005-04-23
8
Medium Priority
?
385 Views
Last Modified: 2012-06-27
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>
0
Comment
Question by:gdlp2004
  • 4
  • 4
8 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 13851554
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
 

Author Comment

by:gdlp2004
ID: 13851558
How about as a request variable?
0
 

Author Comment

by:gdlp2004
ID: 13851563
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 13851567
Saving a request variable is much better :

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

and then to retrieve the variable:

Response.write(Session("strRequestVariable"))

FtB
0
 

Author Comment

by:gdlp2004
ID: 13851579
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
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 900 total points
ID: 13851583
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
 

Author Comment

by:gdlp2004
ID: 13851590
That will work.  Thanks!
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 13851619
Glad to have helped,

FtB
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month19 days, 5 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question