private void update_student() { MySqlCommand commandDatabase = new MySqlCommand("", databaseConnection); commandDatabase.CommandTimeout = 60; try { student stud = new student(); stud.Id_student = text_id_student.Text; String id_student = stud.Id_student; stud.Name = text_name_student.Text; String name = stud.Name; // Form1.SetValueForText2 = text_name_student.Text; stud.Number_of_brothers = "0"; String number_of_brothers = stud.Number_of_brothers; stud.Date_of_birth = bearth_day.Text; String date_of_birth = stud.Date_of_birth; stud.Address = text_addres_student.Text; String address = stud.Address; stud.Phone_number = text_phone_student.Text; String phone_number = stud.Phone_number; stud.Emergency_phone_number = text_phone_emargancy_student.Text; String emergency_phone_number = stud.Emergency_phone_number; stud.Start_date = this.start_date.Text; String start_date = stud.Start_date; stud.End_date = this.end_date.Text; String end_date = stud.End_date; stud.Comments = text_comment_student.Text; String comments = stud.Comments; if (radioButton_male.Checked == true) { stud.Gender = "ذكر"; } else if (radioButton_femal.Checked == true) { stud.Gender = "أنثى"; } String gender = stud.Gender; if (radioButton_not_noob.Checked == true) { stud.Noob = "غير مستجد"; } else if (radioButton_noob.Checked == true) { stud.Noob = "مستجد"; } String noob = stud.Noob; if (radioButton4.Checked == true) { stud.Persistent = "غير مستمر"; } else if (radioButton_presistent.Checked == true) { stud.Persistent = "مستمر"; } String presistent = stud.Persistent; int select = comboBox_transporation.SelectedIndex; string id_transportions = ""; for (int i = 0; i < 2000; i++) { if (select == i) { id_transportions = id_transporation[i]; } } int select_section = comboBox_section.SelectedIndex; string id_sections = ""; for (int i = 0; i < 2000; i++) { if (select_section == i) { id_sections = id_section[i]; } } int select_class = comboBox_class.SelectedIndex; string id_classes = ""; for (int i = 0; i < 2000; i++) { if (select_class == i) { id_classes = id_class[i]; } }//id_student ,name,gender,class_st,section,transporation_id,persistent,noob,comments,end_date,start_date, emergency_phone_number,phone_number,address , date_of_birth,number_of_brothers commandDatabase.CommandText = "Update student set id_student='" + id_student + "',name ='" + name + "',gender='" + gender + "',class_st='" + id_classes + "',section='" + id_sections + "',transporation_id='" + id_transportions + "',persistent='" + presistent + "',noob='" + noob + "',comments='" + comments + "',end_date='" + end_date + "',start_date='" + start_date + "',emergency_phone_number='" + emergency_phone_number + "',phone_number='" + phone_number + "',address='" + address + "',date_of_birth='" + date_of_birth + "',number_of_brothers='" + number_of_brothers + "'WHERE id ='" + id_studente + "'"; commandDatabase.ExecuteNonQuery(); commandDatabase.Dispose(); //MessageBox.Show("Query successfully excuted"); } catch (Exception ex) { MessageBox.Show("Query Error :" + ex.Message); } }
private void insert_student() { string query = txt_student_id.Text; //if (query == "") //{ // MessageBox.Show("Please insert some sql query"); // return; //} MySqlCommand commandDatabase = new MySqlCommand(query, databaseConnection); commandDatabase.CommandTimeout = 60; try { student student = new student(); student.Id_student = txt_student_id.Text; String id_student = student.Id_student; student.Name = txt_name.Text; String name = student.Name; // Form1.SetValueForText2 = textBox2.Text; student.Number_of_brothers = "0"; String number_of_brothers = student.Number_of_brothers; student.Date_of_birth = dateTimePicker1.Text; String date_of_birth = student.Date_of_birth; student.Address = txt_adderes.Text; String address = student.Address; student.Phone_number = txt_phone_number.Text; String phone_number = student.Phone_number; student.Emergency_phone_number = txt_emergency_phone_number.Text; String emergency_phone_number = student.Emergency_phone_number; student.Start_date = dateTimePicker2.Text; String start_date = student.Start_date; student.End_date = dateTimePicker3.Text; String end_date = student.End_date; student.Comments = txt_comments.Text; String comments = student.Comments; if (radio_button_male.Checked == true) { student.Gender = "ذكر"; } else if (radio_button_female.Checked == true) { student.Gender = "أنثى"; } String gender = student.Gender; if (radio_button_new.Checked == true) { student.Noob = "مستجد"; } else if (radio_button_not_new.Checked == true) { student.Noob = "غير مستجد"; } String noob = student.Noob; if (radio_button_persistent.Checked == true) { student.Persistent = "مستمر"; } else if (radio_button_not_persistent.Checked == true) { student.Persistent = "غير مستمر"; } String presistent = student.Persistent; String sql1, id_class = ""; String sql2, id_section = ""; String name_class = txt_class.SelectedItem.ToString(); String name_section = txt_section.SelectedItem.ToString(); sql1 = "SELECT id,name FROM class_st WHERE name='" + name_class + "' "; sql2 = "SELECT id,name FROM section WHERE name='" + name_section + "' "; MySqlCommand command1; command1 = new MySqlCommand(sql1, databaseConnection); MySqlCommand command2; command2 = new MySqlCommand(sql2, databaseConnection); MySqlDataReader myaReader1 = command1.ExecuteReader(); while (myaReader1.Read()) { //ID id_class = id_class + myaReader1.GetString(0) + "\n"; } myaReader1.Close(); MySqlDataReader myaReader2 = command2.ExecuteReader(); while (myaReader2.Read()) { //ID id_section = id_section + myaReader2.GetString(0) + "\n"; } myaReader2.Close(); int select = txt_area.SelectedIndex; string id_transportion = ""; for (int i = 0; i < 2000; i++) { if (select == i) { id_transportion = id_transporation[i]; } } commandDatabase.CommandText = "INSERT INTO student(id,id_student, name,gender, class_st, section, number_of_brothers, date_of_birth, address, phone_number, emergency_phone_number, start_date, end_date, comments, noob,persistent,transporation_id)VALUES(NULL,'" + id_student + "','" + name + "','" + gender + "','" + id_class + "','" + id_section + "','" + number_of_brothers + "','" + date_of_birth + "','" + address + "','" + phone_number + "','" + emergency_phone_number + "','" + start_date + "','" + end_date + "','" + comments + "','" + noob + "','" + presistent + "','" + id_transportion + "')"; commandDatabase.ExecuteNonQuery(); commandDatabase.Dispose(); MessageBox.Show("تم تسجيل المعلومات من فضلك أكمل عملية التسجيل"); } catch (Exception e) { MessageBox.Show("Query Error :" + e.Message); } }