how to use session object in a class

Discussion in 'ASP .Net' started by semesm22, Dec 8, 2005.

  1. semesm22

    semesm22 Guest

    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

    --
    Sent via .NET Newsgroups
    http://www.dotnetnewsgroups.com
    semesm22, Dec 8, 2005
    #1
    1. Advertising

  2. 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.
    Bob Barrows [MVP], Dec 8, 2005
    #2
    1. Advertising

  3. semesm22

    semesm22 Guest

    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



    --
    Sent via .NET Newsgroups
    http://www.dotnetnewsgroups.com
    semesm22, Dec 8, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Smythe
    Replies:
    3
    Views:
    1,228
    Jeff Smythe
    Jan 2, 2004
  2. E11
    Replies:
    1
    Views:
    4,716
    Thomas Weidenfeller
    Oct 12, 2005
  3. momo898
    Replies:
    2
    Views:
    485
    bruce barker \(sqlwork.com\)
    Oct 12, 2006
  4. Don Miller
    Replies:
    4
    Views:
    580
    Don Miller
    Feb 6, 2007
  5. =?Utf-8?B?Um9iSEs=?=
    Replies:
    4
    Views:
    5,254
    =?Utf-8?B?Um9iSEs=?=
    Apr 11, 2007
Loading...

Share This Page