Monday, March 26, 2012

Session Variable Data Type

Hi

I wanna know what is the datatype of the session variables. Can session variable be Integer or string
for examlple, is it true to right
session("v1")=1
or it must be
session("v1")= "1"

RegardsHello there,
Why dont you check the type of the session variable before assigning it; using
something like this:


Session("v1").GetType()

Cheerz
You can lookup the HttpSessionState object's propertieshere.

You'll find that theItem property is of type Object.

Therefore, session variables can have any data type, Integer, String, or even a DataSet for example (although you should keep the size of session as small as possible).

Jos
Session returns or sets an object value, so an object can be either, in each of their appropriate formats. If you have option explicit set to on, you will have to convert the session value to the appropriate type when retrieving the value FROM the session.

Brian
Session can be used to store any object type. When retrieving from session, the object must be cast to its original type before it is used. Here are some examples:


'Storing in session:
Session("v1") = 1
Session("v2") = "This is a string"
Dim ht As Hashtable = GetUsersInRole ("Administrators")
Session("v3") = ht

'Retrieving from session:
Dim var1 As Integer = CInt(Session("v1"))
Dim var2 As String = CStr(Session("v2"))
Dim var3 As HashTable = CType(Session("v3"), Hashtable)

0 comments:

Post a Comment