11
Answers

object reference is not set to an instance of object

Mark Tabor

Mark Tabor

3y
726
1

public JsonResult UpdateStudent(string FirstName,String LastName,string Gender)

{

StudentEntities MYDB=new StudentEntities();

var FindStudents=(from std  in MYDB.students where studentId=id select std).FirstorDefault();

if(FindStudents==null)

{

Student mystudent=new Student();

FindStudents.FirstName=FirstName;

FindStudents.LastName=LastName

}

where running this above code  I get exception as object reference is not set to an instance of object on the bold line 

and  my FindStudents variable is null from Linq query anyone can help 

}

Answers (11)