Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public bool CheckUser(string empCode)
        {

            if (empCode == exdb.Emp_Id.ToString())
            {
                var validate = from user in taxEntity.Users
                               where (user.Code == exdb.Emp_Id.ToString())
                               select user;

                if (validate.Any())
                {
                    User userDetails = new User();
                    userDetails = validate.FirstOrDefault();
                    Session["userDetails"] = userDetails;
                    Response.Redirect("~/TS.aspx");
                }
                else
                {
                    lblMessage.Visible = true;
                    lblMessage.Text = "Please enter correct Employee Code and Password";
                }





            }





Object reference not set to an instance of an object.
Posted
Comments
Mario Majčica 28-Jun-12 3:50am    
Where the code stops? At which point?
Rahul Rajat Singh 28-Jun-12 3:54am    
Which line is giving this exception?
Yatin chauhan 28-Jun-12 5:10am    
In Which line this error occured?????
2011999 28-Jun-12 6:26am    
if (empCode == exdb.Emp_Id.ToString())
Mohammad Reza Valadkhani 29-Jun-12 1:33am    
set a break point to determine where null reference happend !

Object reference not set to an instance of an object

This error happens when you try to use a property or call a method of an object that is null. More details: here[^]

A simple use of Visual studio DEBUGGER can tell you the object because of which it is happening. Just look at the stack trace and put a debugger on that line. Check the objects of that line and see if any one is null and you are trying to use that objects property. Handle the same.

For now, possible places:
exdb.Emp_Id.ToString(),
taxEntity.Users,
validate.Any()


Try!
 
Share this answer
 
Check whether the object exdb is initialized or not.
 
Share this answer
 
Comments
2011999 28-Jun-12 4:47am    
initialized
hi,
Please check this two variable is initialize or not.
taxEntity.Users  // Is it initialise?
exdb   // Is it initialise? 
 
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