public void DeleteStudent(int userId) { var deleteStudent = "DELETE FROM students WHERE userId = @userId"; SqlCommand commandDeleteStudent = new SqlCommand(deleteStudent, connection); commandDeleteStudent.Parameters.AddWithValue("@userId", userId); connection.Open(); commandDeleteStudent.ExecuteNonQuery(); connection.Close(); var grades = repository.GetStudentGrades(userId); foreach (Grade grade in grades) { repository.DeleteGrade(grade.ID); } DeleteUser(userId); }