public void ModifyCity(CityObj cityObj) { using (helper = new SqlHelper()) { helper.AddIntParameter("@CityID", cityObj.CityID); helper.AddIntParameter("@ProvinceID", cityObj.ProvinceID); helper.AddStringParameter("@CityName", 100, cityObj.CityName); string sql = "update City set CityName=@CityName,ProvinceID=@ProvinceID where CityID=@CityID"; helper.ExecuteNonQuery(sql, CommandType.Text); } }
public void AddCity(CityObj cityObj) { using (helper = new SqlHelper()) { SqlParameter idParam = helper.AddOutputParameter("@CityID"); helper.AddStringParameter("@CityName", 100, cityObj.CityName); helper.AddIntParameter("@ProvinceID", cityObj.ProvinceID); helper.ExecuteNonQuery("insert into City (CityName,ProvinceID) values (@CityName,@ProvinceID) select @CityID=@IDENTITY", CommandType.Text); cityObj.CityID = (int)idParam.Value; } }
public CityObj GetCity(int cityId) { using (helper = new SqlHelper()) { helper.AddIntParameter("@CityID", cityId); string sql = "select ProvinceID,CityName from City where CityID=@CityID"; using (SqlDataReader dr = helper.ExecuteReader(sql, CommandType.Text)) { if (dr.HasRows && dr.Read()) { CityObj cityObj = new CityObj(); cityObj.CityID = cityId; cityObj.ProvinceID = (int)dr[0]; cityObj.CityName = (string)dr[1]; return(cityObj); } return(null); } } }
public void ModifyCity(CityObj cityObj) { dal.ModifyCity(cityObj); }
public void AddCity(CityObj cityObj) { dal.AddCity(cityObj); }