// Thêm mới Slide public int InsertSlideImage(SlideImage slideimage) { int i; using (SqlConnection con = new SqlConnection(Const.Connectring)) { con.Open(); SqlCommand cmd = new SqlCommand("InsertSlideImage", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@SlideId", Int32.Parse(slideimage.SlideId.ToString())); cmd.Parameters.AddWithValue("@SlideImageName", slideimage.SlideImageName.ToString()); i = cmd.ExecuteNonQuery(); } return(i); }
// láy slide theo id public SlideImage GetSlideById(int id) { SlideImage c = new SlideImage(); using (SqlConnection con = new SqlConnection(Const.Connectring)) { con.Open(); SqlCommand cmd = new SqlCommand("GetSlideById", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@SlideId", id); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { c.SlideId = Int32.Parse(reader["SlideId"].ToString()); c.SlideImageName = reader["SlideImageName"].ToString(); } return(c); } }
// Cập nhật slide public int UpdateSlide(SlideImage slide) { int i; using (SqlConnection con = new SqlConnection(Const.Connectring)) { con.Open(); SqlCommand cmd = new SqlCommand("UpdateSlide", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@SlideId", Int32.Parse(slide.SlideId.ToString())); cmd.Parameters.AddWithValue("@SlideImageName", slide.SlideImageName.ToString()); // Check NewsImage là null thì truyền null if (slide.SlideImageName == null) { cmd.Parameters.AddWithValue("@SlideImageName", DBNull.Value); } else { cmd.Parameters.AddWithValue("@SlideImageName", slide.SlideImageName); } i = cmd.ExecuteNonQuery(); } return(i); }