The one thing i think might be causing the problem is if there're no results in the reader you should take a look at this code
public bool GetEmployeeDetails(Teacher teacher)
{
using (SqlConnection loginCon = new SqlConnection(ConString))
{
SqlCommand LoginCmd = new SqlCommand
("procGetTeacherDetails", loginCon);
LoginCmd.CommandType = CommandType.StoredProcedure;
LoginCmd.Parameters.Add(new SqlParameter
("@Name", SqlDbType.NChar, (30)));
LoginCmd.Parameters.Add(new SqlParameter
("@Surname", SqlDbType.NChar, (30)));
LoginCmd.Parameters.Add(new SqlParameter
("@RoleID", SqlDbType.Int ));
LoginCmd.Parameters["@Surname"].Value = teacher.Surname;
LoginCmd.Parameters["@Name"].Value = teacher.Name;
LoginCmd.Parameters["@RoleID"].Value = teacher.Role;
loginCon.Open();
SqlDataReader reader = LoginCmd.ExecuteReader();
if(reader.HasRows)
{
reader.Read();
teacher.DateEmployed= reader["DateEmployed"]),
reader.Close();
return true;}
return false;
}
this way you pass your teacher object by reference and the values will be assigned if you find the teacher and it will return true showing it's found and false if nothing is found. and by returning a boolean you presentation layer will know whether teacher is found or not and can also react appropriately
Adding the reader.HasRows in the if statement make your code safer cause you won't be trying access the reader when it's empty, this might be the cause of your code returning null