private void btnSave_Click(object sender, EventArgs e) { int er = 0; if (txtName.Text == "") { er++; ep.SetError(txtName, "Required"); } if (cmbCountry.SelectedValue == null || cmbCountry.SelectedValue.ToString() == "") { er++; ep.SetError(cmbCountry, "Required"); } if (er > 0) { return; } DAL.City city = new DAL.City(); city.Id = Id; city.Name = txtName.Text; city.CountryId = Convert.ToInt32(cmbCountry.SelectedValue); if (city.Update()) { MessageBox.Show(@"Data Updated"); } else { MessageBox.Show(city.Error); } }
private void buttonSave_Click(object sender, EventArgs e) { int error = 0; errorProvider.Clear(); if (textBoxName.Text == "") { error++; errorProvider.SetError(textBoxName, "Required"); } if (comboBoxCountry.SelectedValue == null || comboBoxCountry.SelectedValue.ToString() == "") { error++; errorProvider.SetError(comboBoxCountry, "Required"); } if (error > 0) { return; } cityEdit.Name = textBoxName.Text; cityEdit.CountryId = Convert.ToInt32(comboBoxCountry.SelectedValue); if (cityEdit.Update()) { MessageBox.Show("City is Update."); textBoxName.Text = ""; comboBoxCountry.Text = ""; textBoxName.Focus(); } else { MessageBox.Show(cityEdit.Error); } }