public string InsertCountryDetailed(Country aCountry) { int isSuccess = aCountryGateway.InsertCountry(aCountry); if (isSuccess>0) { return "Country has been successfully added."; } else { return "Sorry Country has not been added."; } }
protected void countrySaveButton_Click(object sender, EventArgs e) { Country aCountry = new Country() { CountryName = Request.Form["countryName"], CountryAbout = Request.Form["editor1"] }; string msg = aCountryManager.InsertCountryDetailed(aCountry); insertMessageShowLabel.Text = msg; LoadCountryInGridView(); }
public List<Country> GetCountries() { SqlConnection aConnection = new SqlConnection(connectionString); string query = "SELECT * FROM tbl_Country"; SqlCommand aCommand = new SqlCommand(query, aConnection); aConnection.Open(); SqlDataReader aReader = aCommand.ExecuteReader(); List<Country> countries = new List<Country>(); while (aReader.Read()) { Country aCountry = new Country() { CountryId = Convert.ToInt32(aReader["CountryId"].ToString()), CountryName = aReader["CountryName"].ToString(), CountryAbout = aReader["CountryAbout"].ToString() }; countries.Add(aCountry); } return countries; }
public int InsertCountry(Country aCountry) { SqlConnection aConnection = new SqlConnection(connectionString); string query = "INSERT INTO tbl_Country(CountryName,CountryAbout) VALUES(@countryName,@countryAbout)"; aConnection.Open(); SqlCommand aCommand = new SqlCommand(); aCommand.Connection = aConnection; aCommand.CommandText = query; aCommand.Parameters.AddWithValue("@countryName", aCountry.CountryName); aCommand.Parameters.AddWithValue("@countryAbout", aCountry.CountryAbout); int rowEffect = aCommand.ExecuteNonQuery(); aConnection.Close(); return rowEffect; }