private void OnOKClick(object sender, EventArgs e) { try { #region InsertRegion SqlConnection con = Connection_Methods.CreateConnection(); DateTime date = dateTimePicker2.Value.Date; string query = "INSERT INTO tbl_teacher (Teacher_Id, Full_Name, Age, Address, Date_Of_Birth, Designation , Salary ,Educational_Qualification, Phone,Email) VALUES (" + textbox_Techer_ID.Text + ", '" + textbox_Name.Text + "', " + textbox_Age.Text + ", '" + textbox_Address.Text + "', '" + date + "', '" + textbox_Designation.Text + "', " + textbox_salary.Text + " , '" + textBox_teacher_quality.Text + "','" + textbox_Phone.Text + "' , '" + textbox_Email.Text + "')"; SqlCommand cmd = new SqlCommand(query, con); SqlDataReader r = cmd.ExecuteReader(); // cmd.Parameters.AddWithValue("Tea") // cmd.Parameters.AddWithValue("@id", id.Text); r.Close(); // MessageBox.Show("Teacher Info Saved.", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Confirm saved?", "Save Record", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); //con.Close(); // ShowOnDataGridView(); Clear(); #endregion } catch (Exception ex) { MessageBox.Show("Please fill the form."); } }
private void cls_comboBox_term_SelectedIndexChanged(object sender, EventArgs e) { if (!cls_comboBox_term.Equals("all")) { SqlConnection conn = Connection_Methods.CreateConnection(); string query = "Select * From result Where class = '" + cls_comboBox_class.Text + "'and term = '" + cls_comboBox_term.Text + "' "; SqlCommand cmd = new SqlCommand(query, conn); SqlDataReader r = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(r); dataGridView1.DataSource = dt; } else if (cls_comboBox_term.Equals("All")) { MessageBox.Show("oppa"); SqlConnection conn = Connection_Methods.CreateConnection(); string query1 = "Select * From result as S , result as T Where class = '" + cls_comboBox_class.Text + "'and S.Student_Id = T.Student_Id "; SqlCommand cmd = new SqlCommand(query1, conn); SqlDataReader r = cmd.ExecuteReader(); DataTable dt1 = new DataTable(); dt1.Load(r); dataGridView1.DataSource = dt1; } }
private void updateStudentForm_Load(object sender, EventArgs e) { try { SqlConnection conn1 = Connection_Methods.CreateConnection(); String query = "select * from tbl_student where Student_Id='" + ID + "'"; SqlCommand cmd = new SqlCommand(query, conn1); SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); textBox_ID.Text = reader[0].ToString(); text_Name.Text = reader[1].ToString(); Class_comboBox.Text = reader[2].ToString(); text_Age.Text = reader[3].ToString(); text_Address.Text = reader[4].ToString(); dateTimePicker1.Text = reader[5].ToString(); comboBox_gender.Text = reader[6].ToString(); textBox_Gurdian.Text = reader[7].ToString(); textBox_G_Id.Text = reader[8].ToString(); comboBox_relationship.Text = reader[9].ToString(); comboBox_quata.Text = reader[10].ToString(); textBox_G_Phone.Text = reader[11].ToString(); textBox_G_Email.Text = reader[12].ToString(); textBox_nationality.Text = reader[13].ToString(); // MessageBox.Show("Confirm delete?", "Save Record", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); //cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Refresh_Click_1(object sender, EventArgs e) { SqlConnection conn = Connection_Methods.CreateConnection(); String query = "select * from tbl_student "; SqlDataAdapter ad = new SqlDataAdapter(query, conn); DataTable ds = new DataTable(); ad.Fill(ds); dataGridView_search.DataSource = ds; }
private void On_Add_Click(object sender, EventArgs e) { SqlConnection conn1 = Connection_Methods.CreateConnection(); string query = "INSERT INTO tbl_class (Class_Name, Class_Teacher, Room_Number) VALUES ('" + textBox_cls_Name.Text + "', '" + textBox_cls_teacher.Text + "','" + textBoxroom_No.Text + "' )"; SqlCommand cmd = new SqlCommand(query, conn1); SqlDataReader r = cmd.ExecuteReader(); r.Close(); MessageBox.Show("Data Saved !!.", "Confirmation", MessageBoxButtons.OK); clear(); }
private void On_Term(object sender, EventArgs e) { SqlConnection conn = Connection_Methods.CreateConnection(); string query = "Select * From result Where Student_Id = '" + st_textBox_Stu_ID.Text + "'and class = '" + st_comboBox_class.Text + "' and term = '" + st_comboBox_term.Text + "' "; SqlCommand cmd = new SqlCommand(query, conn); SqlDataReader r = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(r); dataGridView1.DataSource = dt; }
public void SaveInformation(string query) { try { SqlConnection Conn = Connection_Methods.CreateConnection(); SqlCommand cmd = new SqlCommand(query, Conn); cmd.ExecuteNonQuery(); Conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void search_comboBox_SelectedValueChanged(object sender, EventArgs e) { SqlConnection con = Connection_Methods.CreateConnection(); string query = "Select * From tbl_student Where Class_name = '" + search_comboBox.Text + "'"; SqlCommand cmd = new SqlCommand(query, con); SqlDataReader r = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(r); dataGridView_search.DataSource = dt; }
private void button1_Click(object sender, EventArgs e) { // MessageBox.Show("No message."); try { int match = 0; SqlConnection con = Connection_Methods.CreateConnection(); String query1 = "select Full_Name from tbl_teacher"; SqlCommand cmd = new SqlCommand(query1, con); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { if (reader["Full_Name"].ToString().Equals(textbox_search_teacher_name.Text)) { match = 1; break; } } con.Close(); if (match == 1) { if (textbox_search_teacher_name.Text == "") { MessageBox.Show("Do not match Name"); } else { SqlConnection conn = Connection_Methods.CreateConnection(); String query = "select Full_Name, Address, Designation, Educational_Qualification, Phone, Email from tbl_teacher WHERE Full_Name='" + textbox_search_teacher_name.Text + "'"; SqlDataAdapter ad = new SqlDataAdapter(query, conn); DataTable ds = new DataTable(); ad.Fill(ds); dataGridView1_search.DataSource = ds; } } else { MessageBox.Show("Do not match Teacher Name!!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } // MessageBox.Show("No messege"); }
private void ShowOnDataGridView() { SqlConnection con = Connection_Methods.CreateConnection(); string query = "Select * From tbl_student"; SqlCommand cmd = new SqlCommand(query, con); SqlDataReader r = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(r); // dataGridView1.DataSource = dt; r.Close(); }
private void delete_Click_1(object sender, EventArgs e) { try { SqlConnection conn1 = Connection_Methods.CreateConnection(); String query = "delete from tbl_student where Name='" + text_search_name.Text + "' and Student_ID='" + text_search_Student_Id.Text + "'"; SqlCommand cmd = new SqlCommand(query, conn1); MessageBox.Show("Confirm delete?", "Save Record", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void OnClickSubjectSearch(object sender, EventArgs e) { try { int match = 0; SqlConnection con = Connection_Methods.CreateConnection(); String query1 = "select Subject_name, Class_name from tbl_subject"; SqlCommand cmd = new SqlCommand(query1, con); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { if (reader["Class_name"].ToString().Equals(class_search_comboBox.Text) && reader["Subject_name"].ToString().Equals(Sub_comboBox2.Text)) { match = 1; break; } } con.Close(); if (match == 1) { if (class_search_comboBox.Text == "" && Sub_comboBox2.Text == "") { MessageBox.Show("Did not match Subject name"); } else { SqlConnection conn = Connection_Methods.CreateConnection(); String query = "select * from tbl_subject WHERE Subject_name='" + Sub_comboBox2.Text + "'and Class_name='" + class_search_comboBox.Text + "'"; SqlDataAdapter ad = new SqlDataAdapter(query, conn); DataTable ds = new DataTable(); ad.Fill(ds); dataGridViewSubject.DataSource = ds; } } else { MessageBox.Show("Did not match Subject"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void On_Ok_Click(object sender, EventArgs e) { try { SqlConnection conn1 = Connection_Methods.CreateConnection(); string query = "INSERT INTO result (Student_Id, class, term, bangla, english, math , science ,social_science, religion, pt, music) VALUES (" + textBox_std_Id.Text + ", '" + comboBox_class.Text + "', '" + comboBox_term.Text + "', " + textBox_bangla.Text + ", " + textBox_english.Text + ", " + textBox_math.Text + ", " + textBoxscience.Text + ", " + textBox_social_sci.Text + "," + textBox8_religion.Text + "," + textBox10_pt.Text + "," + textBox9_music.Text + ")"; SqlCommand cmd = new SqlCommand(query, conn1); SqlDataReader r = cmd.ExecuteReader(); r.Close(); MessageBox.Show("Data Saved !!.", "Confirmation", MessageBoxButtons.OK); clear(); } catch (Exception ex) { //MessageBox.Show(ex.Message); MessageBox.Show(ex.Message); } }
private void OnSearchClick(object sender, EventArgs e) { // MessageBox.Show("This name and id is not availabl."); try { int match = 0; SqlConnection con1 = Connection_Methods.CreateConnection(); String query1 = "select Student_Id, Name from tbl_student"; SqlCommand cmd = new SqlCommand(query1, con1); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { if ((reader["Student_Id"].ToString().Equals(text_search_Student_Id.Text)) && reader["Name"].ToString().Equals(text_search_name.Text)) { match = 1; break; } } con1.Close(); if (match == 1) { if (text_search_Student_Id.Text == "" || text_search_name.Text == "") { MessageBox.Show("Write The Appropriate Data"); } else { SqlConnection conn = Connection_Methods.CreateConnection(); String query = "select * from tbl_student WHERE Student_ID='" + text_search_Student_Id.Text + "' and Name='" + text_search_name.Text + "'"; SqlDataAdapter ad = new SqlDataAdapter(query, conn); DataTable ds = new DataTable(); ad.Fill(ds); dataGridView_search.DataSource = ds; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void On_Add_Click(object sender, EventArgs e) { try { DateTime date = dateTimePicker2.Value.Date; SqlConnection conn1 = Connection_Methods.CreateConnection(); String query = "update tbl_teacher set Full_Name='" + textbox_Name.Text + "',Age=" + textbox_Age.Text + ",Address='" + textbox_Address.Text + "',Date_Of_Birth= '" + date + "', Designation='" + textbox_Designation.Text + "',Salary = " + textbox_salary.Text + ", Educational_Qualification='" + textBox_eduQuality.Text + "',Phone='" + textbox_Phone.Text + "',Email='" + textbox_Email.Text + "' where Teacher_Id = '" + ID + "'"; SqlCommand cmd = new SqlCommand(query, conn1); cmd.ExecuteNonQuery(); MessageBox.Show("Confirm Update?", "Save Record", MessageBoxButtons.YesNo); //cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void UpdateTeacherForm_Load(object sender, EventArgs e) { SqlConnection conn1 = Connection_Methods.CreateConnection(); String query = "select * from tbl_teacher where Teacher_Id='" + ID + "'"; SqlCommand cmd = new SqlCommand(query, conn1); SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); textbox_Techer_ID.Text = reader[0].ToString(); textbox_Name.Text = reader[1].ToString(); textbox_Age.Text = reader[2].ToString(); textbox_Address.Text = reader[3].ToString(); dateTimePicker2.Text = reader[4].ToString(); textbox_Designation.Text = reader[5].ToString(); textbox_salary.Text = reader[6].ToString(); textBox_eduQuality.Text = reader[7].ToString(); textbox_Phone.Text = reader[8].ToString(); textbox_Email.Text = reader[9].ToString(); }
public Boolean Search(string a) { int sh = 0; SqlConnection conn = Connection_Methods.CreateConnection(); SqlCommand cmd = new SqlCommand(a, conn); SqlDataReader reader = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(reader); sh = dt.Rows.Count; if (sh != 0) { return(true); } else { return(false); } }
private void Add_Click_1(object sender, EventArgs e) { try { DateTime date = dateTimePicker1.Value.Date; SqlConnection conn1 = Connection_Methods.CreateConnection(); String query = "update tbl_student set Name='" + text_Name.Text + "',Class_name='" + Class_comboBox.Text + "',Age='" + Convert.ToInt32(text_Age.Text) + "',Address='" + text_Address.Text + "', DOB = '" + date + "',Gender='" + comboBox_gender.Text + "',Gurdian_name='" + textBox_Gurdian.Text + "',G_Id='" + Convert.ToInt32(textBox_G_Id.Text) + "',RelationShip='" + comboBox_relationship.Text + "',Quata='" + comboBox_quata.Text + "',Phone='" + textBox_G_Phone.Text + "',Email='" + textBox_G_Email.Text + "',Nationality='" + textBox_nationality.Text + "' where Student_Id = '" + ID + "'"; SqlCommand cmd = new SqlCommand(query, conn1); cmd.ExecuteNonQuery(); MessageBox.Show("Confirm Update?", "Save Record", MessageBoxButtons.YesNo); //cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void OnAddClick(object sender, EventArgs e) { try { //ssi.Show(); #region InsertRegion SqlConnection conn1 = Connection_Methods.CreateConnection(); DateTime date = dateTimePicker1.Value.Date; string query = "INSERT INTO tbl_student (Student_Id, Name, Class_name, Age, Address, DOB, Gender, Gurdian_name,G_Id, RelationShip, Quata, Phone, Email, Nationality) VALUES (" + text_Studet_ID.Text + ", '" + text_Name.Text + "', '" + Class_comboBox.Text + "', " + text_Age.Text + ", '" + text_Address.Text + "', '" + date + "', '" + comboBox_gender.Text + "', '" + textBox_Gurdian.Text + "'," + textBox_G_Id.Text + ",'" + comboBox_relationship.Text + "','" + comboBox_quata.Text + "'," + textBox_G_Phone.Text + ",'" + textBox_G_Email.Text + "','" + textBox_nationality.Text + "' )"; SqlCommand cmd = new SqlCommand(query, conn1); SqlDataReader r = cmd.ExecuteReader(); r.Close(); MessageBox.Show("Admission Complete !!.", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); //con.Close(); // ShowOnDataGridView(); Clear(); #endregion } catch (Exception ex) { //MessageBox.Show(ex.Message); MessageBox.Show("Add your necessary data."); } }