private void add_btn_Click(object sender, EventArgs e) { Add_Update_Lecturer add_stud_lecturer_frm = new Add_Update_Lecturer(); add_stud_lecturer_frm.update_btn.Visible = false; add_stud_lecturer_frm.add_btn.Visible = true; add_stud_lecturer_frm.heading_lb.Text = "Add Lecturer"; add_stud_lecturer_frm.ShowDialog(); this.lecturer_infoTableAdapter.Fill(this.ttms_dbDataSet1.lecturer_info); }
private void lecturer_info_table_CellClick(object sender, DataGridViewCellEventArgs e) { databaseConnection.Open(); MySqlCommand cmd1 = new MySqlCommand("Select id from lecturer_info where lecturer_id = '" + this.lecturer_info_table.CurrentRow.Cells[0].Value.ToString() + "'", databaseConnection); int id = Convert.ToInt32(cmd1.ExecuteScalar()); databaseConnection.Close(); if (e.ColumnIndex == 4) { string edit = "edit"; Add_Update_Lecturer add_stud_lecturer_frm = new Add_Update_Lecturer(id, this.lecturer_info_table.CurrentRow.Cells[2].Value.ToString(), edit); add_stud_lecturer_frm.lect_reg_textbox.Text = this.lecturer_info_table.CurrentRow.Cells[0].Value.ToString(); add_stud_lecturer_frm.lect_name_textbox.Text = this.lecturer_info_table.CurrentRow.Cells[1].Value.ToString(); add_stud_lecturer_frm.lect_email_textbox.Text = this.lecturer_info_table.CurrentRow.Cells[2].Value.ToString(); add_stud_lecturer_frm.lect_mobile_textbox.Text = this.lecturer_info_table.Rows[e.RowIndex].Cells[3].Value.ToString(); add_stud_lecturer_frm.update_btn.Visible = true; add_stud_lecturer_frm.add_btn.Visible = false; add_stud_lecturer_frm.heading_lb.Text = "Edit Lecturer"; add_stud_lecturer_frm.ShowDialog(); this.lecturer_infoTableAdapter.Fill(this.ttms_dbDataSet1.lecturer_info); } else if (e.ColumnIndex == 5) { if (MessageBox.Show("Are you sure want to delete this record?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { databaseConnection.Open(); DataGridViewRow row = lecturer_info_table.Rows[e.RowIndex]; MySqlCommand cmd = new MySqlCommand("Delete from lecturer_info where lecturer_id = '" + row.Cells[0].Value.ToString() + "'", databaseConnection); cmd.ExecuteNonQuery(); //remove from datatable lecturerinfoBindingSource.RemoveCurrent(); //refresh table this.lecturer_infoTableAdapter.Fill(this.ttms_dbDataSet1.lecturer_info); databaseConnection.Close(); } } }