how to use session object in a class

S

semesm22

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 system.data.ole,
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 method...here 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

try
OleConnection.Open
dim myDataset as new Dataset
DataAdapter.Fill(myDataset)
catch
end try
end class

*************************************************************
now what i would like to do is to assign myDataset to a session
object....is 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 &
"'"
myConnectDB.Login

end class


PLEASE HELP


thank you
sam
 
B

Bob Barrows [MVP]

semesm22 said:
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
 
S

semesm22

thank you very much for your help, here is what i did

***inside the ConnectDB Login() Method
OleConnection.Open()
Dim myDataSet As New DataSet
DataAdapter.Fill(myDataSet)
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
Response.Redirect("test.aspx?purpose=session")
Else
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
sam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top