Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Quote:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.


What I have tried:

  {
Line 29: 
Line 30:             CDT = Cadapter.SELECT_SEARCH_COMPANY(Session["JOBCATE"].ToString(), Session["QUALI"].ToString(), Session["skill"].ToString());
Line 31:             Session["CID"] = CDT.Rows[0]["CID"].ToString();
Line 32:             if (CDT.Rows.Count == 0)
Posted
Updated 25-Jul-17 7:18am
Comments
F-ES Sitecore 26-Jul-17 4:47am    
This question is asked every day so google the error message because the answer and the advice never changes. We can't fix this for you, *you* have to check exactly what is null in your code and then decide the proper way to handle that null.

1 solution

Hi,

This error occurs when the datatable is not referenced.
In your code, the error occurred because the datatable CDT is null and you tried to read it.
C#
Session["CID"] = CDT.Rows[0]["CID"].ToString();


To fix this error.
C#
 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 
   {
       //your code
   }
}
 
Share this answer
 
v2
Comments
sommr0 25-Jul-17 13:29pm    
How to fixed it??
Sheila Pontes
Sheila Pontes 25-Jul-17 13:48pm    
I added the above correction.
sommr0 25-Jul-17 13:55pm    
System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 22: protected void Page_Load(object sender, EventArgs e)
Line 23: {
Line 24: CDT = Cadapter.SELECT_SEARCH_COMPANY(Session["JOBCATE"].ToString(), Session["QUALI"].ToString(), Session["skill"].ToString());
Line 25: if (CDT != null)
Line 26: {

sommr0 25-Jul-17 13:56pm    
Same issue.. i paste your code..

sommr0 25-Jul-17 13:59pm    
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 28: {
Line 29:
Line 30: CDT = Cadapter.SELECT_SEARCH_COMPANY(Session["JOBCATE"].ToString(),Session["QUALI"].ToString(), Session["skill"].ToString());
Line 31: if (CDT != null)
Line 32: {

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900