public string insert_Question(QuestionProvider question) { string user_message; SqlConnection sqlConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connection"].ConnectionString); try { SqlCommand sqlCmd = new SqlCommand("[insert_question]", sqlConnection); sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.Parameters.Add("@question_title", SqlDbType.NVarChar).Value = question.question_title; sqlCmd.Parameters.Add("@question_a", SqlDbType.NVarChar, 200).Value = question.question_a; sqlCmd.Parameters.Add("@question_b", SqlDbType.NVarChar, 200).Value = question.question_b; sqlCmd.Parameters.Add("@question_c", SqlDbType.NVarChar, 200).Value = question.question_c; sqlCmd.Parameters.Add("@question_d", SqlDbType.NVarChar, 200).Value = question.question_d; sqlCmd.Parameters.Add("@question_correct", SqlDbType.NVarChar, 200).Value = question.question_correct; sqlCmd.Parameters.Add("@question_date", SqlDbType.DateTime).Value = question.question_date; sqlCmd.Parameters.Add("@question_fk_teacher", SqlDbType.Int).Value = question.question_fk_teacher; sqlCmd.Parameters.Add("@question_fk_course", SqlDbType.Int).Value = question.question_fk_course; sqlConnection.Open(); sqlCmd.ExecuteNonQuery(); return(user_message = "Success!"); } catch (Exception ex) { MessageBox.Show(ex.Message); return(user_message = "Failure"); } finally { sqlConnection.Close(); } }
private void bt_Add_Click(object sender, RoutedEventArgs e) { QuestionProvider question = new QuestionProvider(); question.question_title = txt_Title.Text; question.question_a = txt_Answer_a.Text; question.question_b = txt_Answer_b.Text; question.question_c = txt_Answer_c.Text; question.question_d = txt_Answer_d.Text; question.question_correct = txt_Answer_correct.Text; question.question_date = System.DateTime.Now; question.question_fk_teacher = TeacherLogin.teacher_uid; question.question_fk_course = cbox_Course.SelectedIndex + 1; AddQuestionHandler addQuestionHandler = new AddQuestionHandler(); string user_message = addQuestionHandler.insert_Question(question); MessageBox.Show(user_message); }