private void searchButton_Click(object sender, EventArgs e) { DAL.City aCity = new DAL.City(); aCity.Search = searchTextBox.Text; try { aCity.CountryId = Convert.ToInt32(countryNameComboBox.SelectedValue); } catch { } searchDataGridView.DataSource = aCity.Select().Tables[0]; }
private void saveButton_Click(object sender, EventArgs e) { int error = 0; aErrorProvider.Clear(); if (cityNameTextBox.Text == "") { error++; aErrorProvider.SetError(cityNameTextBox, "Requred"); } if (countryNameComboBox.SelectedValue == null || countryNameComboBox.SelectedValue.ToString() == "") { error++; aErrorProvider.SetError(countryNameComboBox, "Requred"); } if (error > 0) { return; } DAL.City aCity = new DAL.City(); aCity.Name = cityNameTextBox.Text; aCity.CountryId = Convert.ToInt32(countryNameComboBox.SelectedValue); if (aCity.Insert()) { MessageBox.Show("Data Saved"); cityNameTextBox.Text = ""; countryNameComboBox.SelectedValue = -1; cityNameTextBox.Focus(); } else { MessageBox.Show(aCity.Error); } }