Mark Tabor

Mark Tabor

  • 585
  • 2k
  • 460.9k

object reference is not set to an instance of object

Jan 11 2022 7:46 PM

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)