Showing posts with label details. Show all posts
Showing posts with label details. Show all posts

Thursday, March 22, 2012

Structures in Session variables

Is it possible to store structures in Session variables?

I want to store some basic user details in a Session variable (first name, last name, join date, etc) and thought it would be easier to put them into a structure rather than holding them in separate variables.

Is this possible?

How do I do it?Hi,
You can put in Session anything that inherits from System.Object. In .NET it is virtually everithing (except interfaces and delegates) including structures. Having structure str you can do it like this:


Session("MyStruct") = str

Thanks.

If I subsequently want to delete the structure from the Session, can I just set Session("MyStruct") = null ?

Will this release all the individual components of the structure in one go?
Yes

Structures vs Variables - Or can I even do this?

Hello all-
I need to pass around the details of a db record a few times and was wondering about using structures. If I create a structure something like the one listed below in one of my XXX.vb files, can I use it like a variable?

**USERDB.VB File**
Public Structure UserDetails
puplic FirstName as string
public LastName as string
End Structure

Public Function GetUserDetails(byval UID as Integer) as UserDetails
**Database crap here**
GetUserDetails.FirstName = objDR("FirstName").tostring
GetUserDetails.LastName = objDR("LastName").tostring
End Function

**WEBFORM1.ASPX.VB**
Private Sub ShowUser(byval UID as integer)
Dim objUserDetails as UserDetails
objUserDetails = GetUserDetails(UID)
lblFirstName.text = objUserDetails.FirstName
lblLastName.text = objUserDetails.LastName
End Sub

Sorry so long. Do I need to destroy the objects when done with them?

Thanks,
DougMaybe use a class instead? Any help would be great!