private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { string colName = dataGridView1.Columns[e.ColumnIndex].Name; try { if (colName == "Edit") { frmAddSalary frm = new frmAddSalary(this); frm.btnSave.Enabled = false; frm.txtEmpId.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); frm.txtName.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); frm.txtSalary.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); frm.ShowDialog(); } else if (colName == "Delete") { if (MessageBox.Show("Are you sure you want to delete this record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { con.Open(); cm = new SqlCommand("Delete from tblSalary where emp_id like '" + dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString() + "'", con); cm.ExecuteNonQuery(); con.Close(); MessageBox.Show("Your record has been successfully deleted!"); LoadRecord(); } } }catch (Exception er) { MessageBox.Show(er.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void pictureBox2_Click(object sender, EventArgs e) { frmAddSalary frm = new frmAddSalary(this); frm.Show(); }