Пример #1
0
        //This adds an entry to the enrollments join table containing IDs for relevant Student and Course objects.
        public void AddStudent(Student newStudent)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"INSERT INTO enrollments (students_id, courses_id) VALUES (@StudentsId, @CoursesId);";
            // cmd.Parameters.AddWithValue("@StudentsId", _id);
            // cmd.Parameters.AddWithValue("@CoursesId", _id);

            MySqlParameter students_id = new MySqlParameter();

            students_id.ParameterName = "@StudentsId";
            students_id.Value         = newStudent.GetStudentId();
            cmd.Parameters.Add(students_id);

            MySqlParameter courses_id = new MySqlParameter();

            courses_id.ParameterName = "@CoursesId";
            courses_id.Value         = _courseId;
            cmd.Parameters.Add(courses_id);

            cmd.ExecuteNonQuery();
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
Пример #2
0
 public override bool Equals(System.Object otherStudent)
 {
     if (!(otherStudent is Student))
     {
         return(false);
     }
     else
     {
         Student newStudent   = (Student)otherStudent;
         bool    idEquality   = this.GetStudentId().Equals(newStudent.GetStudentId());
         bool    nameEquality = this._studentName.Equals(newStudent._studentName);
         return(idEquality && nameEquality);
     }
 }