private void btn_delete_row_Click(object sender, EventArgs e) { try { DialogResult result = MessageBox.Show("Do you want to delete these entry...?", "Confirmation", MessageBoxButtons.YesNoCancel); if (result == DialogResult.Yes) { //... SqlDataReader dr; Common_Class obj = new Common_Class(); obj.openconnection(); int i; i = dgv_cust_master.SelectedCells[0].RowIndex; obj.cmd = new SqlCommand("Select * from Customer_Master where Customer_ID = " + dgv_cust_master.SelectedRows[i].Cells[0].Value.ToString() + " ", obj.con); dr = obj.cmd.ExecuteReader(); if (dr.Read()) { tempid = (int)dr["Customer_ID"]; dr.Close(); } obj.cmd = new SqlCommand("Delete from Customer_Purchase_Detail where Customer_ID = " + tempid + " ", obj.con); obj.cmd.ExecuteNonQuery(); obj.cmd = new SqlCommand("Delete from Customer_Master where Customer_ID = " + tempid + " ", obj.con); if (obj.cmd.ExecuteNonQuery() > 0) { MessageBox.Show("Row Deleted"); // TODO: This line of code loads data into the 'mobile_Shoppee_DBDataSet.Customer_Purchase_Detail' table. You can move, or remove it, as needed. this.customer_Purchase_DetailTableAdapter.Fill(this.mobile_Shoppee_DBDataSet.Customer_Purchase_Detail); // TODO: This line of code loads data into the 'mobile_Shoppee_DBDataSet.Customer_Master' table. You can move, or remove it, as needed. this.customer_MasterTableAdapter.Fill(this.mobile_Shoppee_DBDataSet.Customer_Master); } else { MessageBox.Show("Record Are Not Deleted"); } obj.closeconnection(); obj.cmd.Dispose(); dr.Close(); } } catch (Exception ex) { // Block of code to handle errors MessageBox.Show(ex.Message); } }