Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how to use session object in a class

Thread Tools

how to use session object in a class

Posts: n/a
hello all, i am new to ASP.NET, and sessions....and i would like to do
the following....i have a ConnectDB class, that imports,
and i have the OleConnection, and OleCommand, and a SQL string as a
property in that class....the idea is that i can set the SQL property
from any web form, and call a login method that will connect to the
datebase and select * from client, for example, and put the data in a
Dataset.....what i would like to do is to add this dataset to the
session object, so that i can check to see if there were records found
in the database from the web form that called the Login is
the code i m using, cause i don't think i'm explaining this well!!!

public class ConnectDB

*** i nitialize the connection string, and the OleConnection,
OleCommand, and DataAdapter here***

public sub Login()

'SQL statment set from any page
OleCommand.CommandText = me.SQL
OleCommand.Connection = OleConnection

dim myDataset as new Dataset
end try
end class

************************************************** ***********
now what i would like to do is to assign myDataset to a session this even possible?, if so, how can i do that? if not, then
what is a better solution?
************************************************** **********
public class WebForm1

private sub Login_Click()

dim myConnectDB as new ConnectDB

myConnectDB.SQL = "select * from client where name = '" & txtName.text &

end class


thank you

Sent via .NET Newsgroups
Reply With Quote
Bob Barrows [MVP]
Posts: n/a
semesm22 wrote:
> hello all, i am new to ASP.NET, and sessions....and i would like to do

You have to use an httpContext object in your class. Like this:

Dim curContext As HttpContext = HttpContext.Current
curContext.Session("myDataset") =myDataset

Bob Barrows

Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Reply With Quote
Posts: n/a
thank you very much for your help, here is what i did

***inside the ConnectDB Login() Method
Dim myDataSet As New DataSet
HttpContext.Current.Session("myDataset") = myDataSet

private sub cmdLogin_click()

Dim myDataset As New DataSet
myDataset = Session("myDataset")
If myDataset.Tables(0).Rows.Count = 1 Then
label1.text = "wrong name"
End If
end sub

now, what i want to know is.....the Dataset that i assigned to
Session("myDataset"), is it only alive for the duration of the session?

thank you for your help

Sent via .NET Newsgroups
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Transferring Object from Session Variable to New Class Object??? Don Miller ASP .Net 4 02-06-2007 01:28 PM
Stored Session object is mixed up with another user's session object. momo898 ASP .Net 2 10-12-2006 03:33 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
Passing derived class object array in place of base class object array C++ 9 12-03-2004 10:57 PM