private void Button_Click(object sender, RoutedEventArgs e) { //The following code takes data from the combobox and TextBox and inserts it into the SQL Enrollment Table. try { int courseId; if (EnrollCourseComboBox.SelectedValue != null) { courseId = (int)EnrollCourseComboBox.SelectedValue; bool isEnrolled = studentBL.EnrollInCourse(student.StudentID, courseId); if (isEnrolled) { MessageBox.Show("Enrolled Successfully"); } else { MessageBox.Show("Failed to enroll!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("Please Select A course!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { MessageBox.Show("Already Enrolled!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }