public string InsertCity(City aCity) { int isSuccess= aCityGateway.InsertCity(aCity); if (isSuccess>0) { return "City has successfully insert."; } else { return "Sorry city has not been insert sucessfully."; } }
public int InsertCity(City aCity) { SqlConnection aConnection = new SqlConnection(connectionString); string query = "INSERT INTO tbl_City VALUES(@cityName,@cityAbout,@noOfDewells,@location,@weather,@countryId)"; aConnection.Open(); SqlCommand aCommand = new SqlCommand(); aCommand.Connection = aConnection; aCommand.CommandText = query; aCommand.Parameters.AddWithValue("@cityName", aCity.CityName); aCommand.Parameters.AddWithValue("@cityAbout", aCity.CityAbout); aCommand.Parameters.AddWithValue("@noOfDewells", aCity.NoOfDewells); aCommand.Parameters.AddWithValue("@location", aCity.Location); aCommand.Parameters.AddWithValue("@weather", aCity.Weather); aCommand.Parameters.AddWithValue("@countryId", aCity.CountryId); int rowEffect = aCommand.ExecuteNonQuery(); aConnection.Close(); return rowEffect; }
protected void saveCityButton_Click(object sender, EventArgs e) { City aCity = new City(); aCity.CityName = Request.Form["name"]; // aCity.CityName = cityNameTextBox.Text; aCity.CityAbout = Request.Form["editor1"]; aCity.NoOfDewells = int.Parse(Request.Form["noOfDwellers"]); //aCity.NoOfDewells = int.Parse(noOfDwellersTextBox.Text); aCity.Location = Request.Form["location"]; //aCity.Location = locationTextBox.Text; aCity.Weather = Request.Form["editor2"]; aCity.CountryId = Convert.ToInt32(countryDropDownList.SelectedItem.Value); string insertMessage = aCityManager.InsertCity(aCity); LoadAllCityViews(); showCitySaveMessage.Text = insertMessage; }