Tracking session state within business object class

  • Thread starter Thread starter oj
  • Start date Start date
O

oj

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.
 
Turn on Option Strict
Set a quick watch on your staffMemberDS variable. See what value it has at
runtime.
 
Back
Top