private void add_btn_Click(object sender, EventArgs e)
 {
     using (Add_Update_Student add_stud_lecturer_frm = new Add_Update_Student())
     {
         add_stud_lecturer_frm.update_btn.Visible = false;
         add_stud_lecturer_frm.add_btn.Visible    = true;
         add_stud_lecturer_frm.heading_lb.Text    = "Add Student";
         add_stud_lecturer_frm.ShowDialog();
     }
     LoadStudents();
 }
        private void student_info_table_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            databaseConnection.Open();
            MySqlCommand cmd1 = new MySqlCommand("Select id from student_info where student_reg_no = '" + this.student_info_table.CurrentRow.Cells["registration_no"].Value.ToString() + "'", databaseConnection);
            int          id   = Convert.ToInt32(cmd1.ExecuteScalar());

            databaseConnection.Close();

            if (e.ColumnIndex == student_info_table.Columns["view_btn"].Index)
            {
                Add_Update_Student add_stud_lecturer_frm = new Add_Update_Student(id, this.student_info_table.CurrentRow.Cells["email"].Value.ToString());

                add_stud_lecturer_frm.stud_regnum_textbox.Text = this.student_info_table.CurrentRow.Cells["registration_no"].Value.ToString();
                add_stud_lecturer_frm.stud_name_textbox.Text   = this.student_info_table.CurrentRow.Cells["student_name"].Value.ToString();
                add_stud_lecturer_frm.student_course_stream_combo.SelectedItem = this.student_info_table.CurrentRow.Cells["course_stream"].Value.ToString();
                add_stud_lecturer_frm.stud_email_textbox.Text      = this.student_info_table.CurrentRow.Cells["email"].Value.ToString();
                add_stud_lecturer_frm.stud_mobile_textbox.Text     = this.student_info_table.Rows[e.RowIndex].Cells["mobile_no"].Value.ToString();
                add_stud_lecturer_frm.intake_combobox.SelectedItem = this.student_info_table.CurrentRow.Cells["intake"].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 Student";
                add_stud_lecturer_frm.ShowDialog();

                LoadStudents();
            }

            else if (e.ColumnIndex == student_info_table.Columns["delete_btn"].Index)
            {
                if (MessageBox.Show("Are you sure want to delete this record?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    databaseConnection.Open();
                    MySqlCommand cmd = new MySqlCommand("Delete from student_info where student_reg_no = '" + this.student_info_table.CurrentRow.Cells["registration_no"].Value.ToString() + "'", databaseConnection);
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Delete Successful");
                    databaseConnection.Close();
                    //remove from datatable
                    student_info_table.Rows.Remove(student_info_table.CurrentRow);
                    //refresh table
                    LoadStudents();
                }
            }
        }