c# - Using Session is giving error -
i have aspx
page calling function below
public static string funfillemp(object[] args) { string strprireturn = ""; dataaccesslayer objpridt = new dataaccesslayer(); datatable dt = new datatable(); dt = objpridt.executedatatable("select mkey,emp_name,emp_card_no emp_mst "+ "department_mkey='" + args[0].tostring() + "' , status in ('a','s') , hub_mkey in " + "(select hub_mkey emp_mst e,user_mst u e.mkey=u.employee_mkey , e.status in ('a','s') "+ "and u.mkey='" + session["userid"].tostring().trim() + "') " + "order 2"); if (dt.rows.count > 0) { (int intprii = 0; intprii < dt.rows.count; intprii++) { strprireturn += dt.rows[intprii][0].tostring() + "~" + dt.rows[intprii][1].tostring() + "~" + dt.rows[intprii][2].tostring() + "|"; } } return strprireturn; }
but using session
giving me error as
an object reference required nonstatic field
so how use session here?
you need use httpcontext.current.session["userid"]
since you're accessing inside static
method.
and yes, you'll need handle scenario when not assign session.
Comments
Post a Comment