Tracking session state within business object class

Discussion in 'ASP .Net' started by oj, Nov 24, 2004.

  1. oj

    oj Guest

    Could someone explain to me why the following code snippet throws an
    "Object Reference not set to an instance of an object error":


    public void SetActiveStaffMember(int staffMemberId)

    {

    DAL.StaffMemberDataSet smDS = new DAL.StaffMemberDataSet();

    if(GetStaffMemberById(staffMemberId) == 0)

    smDS = staffMemberDS;

    System.Web.HttpContext.Current.Session["smDS"] = smDS;

    }




    and why the following code does not throw the error:



    public void SetActiveStaffMember(int staffMemberId)

    {

    DAL.StaffMemberDataSet smDS = new DAL.StaffMemberDataSet();

    if(GetStaffMemberById(staffMemberId) == 0)

    smDS = staffMemberDS;

    }




    I would like to track Session state for the dataset member of my
    business object class, but it seems that this is causing the issue.
    Any info. is appreciated.
     
    oj, Nov 24, 2004
    #1
    1. Advertising

  2. Turn on Option Strict
    Set a quick watch on your staffMemberDS variable. See what value it has at
    runtime.

    "oj" wrote:

    > Could someone explain to me why the following code snippet throws an
    > "Object Reference not set to an instance of an object error":
    >
    >
    > public void SetActiveStaffMember(int staffMemberId)
    >
    > {
    >
    > DAL.StaffMemberDataSet smDS = new DAL.StaffMemberDataSet();
    >
    > if(GetStaffMemberById(staffMemberId) == 0)
    >
    > smDS = staffMemberDS;
    >
    > System.Web.HttpContext.Current.Session["smDS"] = smDS;
    >
    > }
    >
    >
    >
    >
    > and why the following code does not throw the error:
    >
    >
    >
    > public void SetActiveStaffMember(int staffMemberId)
    >
    > {
    >
    > DAL.StaffMemberDataSet smDS = new DAL.StaffMemberDataSet();
    >
    > if(GetStaffMemberById(staffMemberId) == 0)
    >
    > smDS = staffMemberDS;
    >
    > }
    >
    >
    >
    >
    > I would like to track Session state for the dataset member of my
    > business object class, but it seems that this is causing the issue.
    > Any info. is appreciated.
    >
     
    =?Utf-8?B?VGFtcGEgLk5FVCBLb2Rlcg==?=, Nov 24, 2004
    #2
    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. shamanthakamani
    Replies:
    1
    Views:
    3,502
    Natty Gur
    Nov 20, 2003
  2. Not Liking Dot Net Today
    Replies:
    0
    Views:
    620
    Not Liking Dot Net Today
    Apr 21, 2004
  3. Maciek
    Replies:
    0
    Views:
    8,259
    Maciek
    Sep 15, 2005
  4. jnickfl1
    Replies:
    0
    Views:
    598
    jnickfl1
    Sep 18, 2006
  5. Harry Haller
    Replies:
    0
    Views:
    1,663
    Harry Haller
    Nov 7, 2006
Loading...

Share This Page