Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting session variable

Status
Not open for further replies.

JSMITH242B

Programmer
Mar 7, 2003
352
GB
Hi Group,
I want to return a recordset in my ASP Page that is limited in the where clause by a session variable.
The datatype is int for data to be stored in the session variable.

This is how I've set the Session variable based on a defined recordset.
Session("schoolid") = objRS.("schoolid")


In my resulting page, I use this in my sql statement

strSql = strSql & " SELECT p.persref, "
strSql = strSql & " p.title, "
strSql = strSql & " p.surname, "
strSql = strSql & " p.firstname, "
strSql = strSql & " p.number, "
strSql = strSql & " p.letter, "
strSql = strSql & " p.addr1, "
strSql = strSql & " p.title, "
strSql = strSql & " p.firstname, "
strSql = strSql & " p.surname, "
strSql = strSql & " p.sex, "
strSql = strSql & " p.schoolid, "
strSql = strSql & " p.famref, "
strSql = strSql & " p.addref, "
strSql = strSql & " p.txtdob, "
strSql = strSql & " p.surgeryid "
strSql = strSql & " FROM person p "
strSql = strSql & " WHERE (dod = '' or dod is null) "
strSql = strSql & " AND p.schoolid = " & Session("schoolid")

when I do a response.write, the SQL statement reads "AND p.schoolid = <blank> " so the Session variable is not being passed/set.

So,
1. Do I need to pass the session variable as a hidden field?
2. What's the best way to pass a session variable from one page to the next
3. Can I use a Session variable if the resultant recordset returns more than one record but ALL values in the field I will use as the Session variable are unique?

Thanks


 
Just to clarify, are you setting this Session variable in the previous page or the same page?

Second question, if you Response.Write the value from the recordset in the same page that you assign it to the Session variable, does it output correctly or is it blank?

First suggestion: If it is being set in one page and used in a second page, output the SessionId value on both pages and make sure it is the same. If it is not the same then you may have cookies turned off, which are used by the server to track the client's SessionId value from page to page. Basically if that cookie doesn't get written you will be starting a new Session on each page and there is no way for the server to know you had a previous session.

-T

barcode_1.gif
 
Setting the Session variable in the previous page.

I will check that the Response.Write outputs correctly in the page I'm setting it in. I checked that the function was invoked but I didn't check the value of the recordset!! oops

In resposne to your suggestion, other Session vriables are loaded correctly just this one that I've added is causing an 'issue'.

Thanks
I'll respond back once I've checked the value from the recordset.

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top