Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am working on a asp.net C# project,
On executing, I get an error and am redirected to the following page
Server Error in '/' Application.
Object reference not set to an instance of an object.
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.

Source Error:

Line 186: clsRoomTemplate_DAL _clsRoomTemplate_DAL = new clsRoomTemplate_DAL();
Line 187: DataTable dtCustomerSelectedItem = _clsRoomTemplate_DAL.PopulateCustomerSelectedItem();
Line 188: if (dtCustomerSelectedItem.Rows.Count > 0)
Line 189: {
Line 190: // string ImagePath = @"/Images/sofa1.jpg"; //Your Image Path


Kindly help
thanks
Posted

Check for nullability

C#
clsRoomTemplate_DAL _clsRoomTemplate_DAL = new clsRoomTemplate_DAL();
if(_clsRoomTemplate_DAL != null)
{
 // your code
}
else
{
// handle exception
}


Hope that helps.
 
Share this answer
 
DataTable dtCustomerSelectedItem = _clsRoomTemplate_DAL.PopulateCustomerSelectedItem();
if (dtCustomerSelectedItem.Rows.Count > 0)
{
       string ImagePath = @"~/Images/sofa1.jpg"; //Your Image Path 
}
 
Share this answer
 

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