private void btnSave_Click(object sender, EventArgs e) { bool Result = DBLayer.CHK_City(txtName.Text); if (CheckField()) { try { if (mode == 1) { if (Result) { MessageBox.Show(txtName.Text + " Already Exist!", "Duplicate", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else { usp_SEL_tblCityTableAdapter.Insert1(txtName.Text); btnCancel.Enabled = false; btnNew.Enabled = true; btnSave.Enabled = false; btnDelete.Enabled = true; btnEdit.Enabled = true; txtName.ReadOnly = true; usp_SEL_tblCityTableAdapter.Fill(comDataSet.usp_SEL_tblCity); mode = 0; DGCity.Enabled = true; btnClose.Show(); MessageBox.Show("Saved Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else if (mode == 0) { if (Old == txtName.Text) { usp_SEL_tblCityTableAdapter.Update1(txtName.Text, Old); btnCancel.Enabled = false; btnNew.Enabled = true; btnSave.Enabled = false; btnDelete.Enabled = true; btnEdit.Enabled = true; txtName.ReadOnly = true; usp_SEL_tblCityTableAdapter.Fill(comDataSet.usp_SEL_tblCity); mode = 0; DGCity.Enabled = true; btnClose.Show(); MessageBox.Show("Modified Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (Result) { MessageBox.Show(txtName.Text + " Already Exist!", "Duplicate", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else { usp_SEL_tblCityTableAdapter.Update1(txtName.Text, Old); btnCancel.Enabled = false; btnNew.Enabled = true; btnSave.Enabled = false; btnDelete.Enabled = true; btnEdit.Enabled = true; txtName.ReadOnly = true; usp_SEL_tblCityTableAdapter.Fill(comDataSet.usp_SEL_tblCity); mode = 0; DGCity.Enabled = true; btnClose.Show(); MessageBox.Show("Modified Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } AcceptButton = btnNew; } }