Amjad Fiaz
asked on
System.NullReferenceException: Object reference not set to an instance of an object.
protected void Page_Load(object sender, EventArgs e)
{
CDT = Cadapter.SELECT_SEARCH_COMPANY(Session["JOBCATE"].ToString(), Session["QUALI"].ToString(), Session["skill"].ToString());
if (CDT != null)
{
if (CDT.Rows.Count > 0)
{
Session["CID"] = CDT.Rows[0]["CID"].ToString();
}
else
{
DataList3.DataSource = CDT;
DataList3.DataBind();
}
}
}
ASKER
but it is a searching from database how i do it?
which line is giving that error?
put a breakpoint and see all the variables and expressions on that line to see what is wrong
put a breakpoint and see all the variables and expressions on that line to see what is wrong
from your codes posted, without the actual logic, few variables to check and make sure they are not null.
As mentioned by HainKurt, place the break points so that you know which line hits the error
- Session["JOBCATE"]
- Session["QUALI"]
- Session["skill"]
- CDT.Rows[0]["CID"]
As mentioned by HainKurt, place the break points so that you know which line hits the error
Your first line makes a lot of assumptions without checking the nullability of many object/property references:
As others have stated, you need to check your many references, namely:
This would essentially look like:
-saige-
CDT = Cadapter.SELECT_SEARCH_COMPANY(Session["JOBCATE"].ToString(), Session["QUALI"].ToString(), Session["skill"].ToString());
As others have stated, you need to check your many references, namely:
- Cadapter
- Session["JOBCATE"]
- Session["QUALI"]
- Session["skill"]
This would essentially look like:
protected void Page_Load(object sender, EventArgs e)
{
var jobcate = Session["JOBCATE"];
var quali = Session["QUALI"];
var skill = Session["skill"];
if (Cadapter != null && jobcate != null && quali != null && skill != null)
{
CDT = Cadapter.SELECT_SEARCH_COMPANY(jobcate.ToString(), quali.ToString(), skill.ToString());
if (CDT != null)
{
if (CDT.Rows.Count > 0)
{
Session["CID"] = CDT.Rows[0]["CID"].ToString();
}
else
{
DataList3.DataSource = CDT;
DataList3.DataBind();
}
}
}
}
-saige-
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
apply the same thing here...
https://www.experts-exchange.com/questions/29049777/System-NullReferenceException-Object-reference-not-set-to-an-instance-of-an-object.html?notificationFollowed=195837547&anchorAnswerId=42250239#a42250239