public NV_Video_ChiTiet GetById(int id) { using (SqlConnection myConnection = new SqlConnection(ConnectionString)) { using (SqlCommand myCommand = new SqlCommand("NV_Video_getByID", myConnection)) { myCommand.CommandType = CommandType.StoredProcedure; SqlParameter pID = new SqlParameter("@id", SqlDbType.Int); pID.Value = id; myCommand.Parameters.Add(pID); NV_Video_ChiTiet model = new NV_Video_ChiTiet(); DataTable dt; myConnection.Open(); using (SqlDataAdapter mData = new SqlDataAdapter(myCommand)) { dt = new DataTable(); mData.Fill(dt); } if (dt != null && dt.Rows.Count > 0) { model = new NV_Video_ChiTiet(dt.Rows[0]); } return(model); } } }
public bool update(NV_Video_ChiTiet model) { using (SqlConnection myConnection = new SqlConnection(ConnectionString)) { using (SqlCommand myCommand = new SqlCommand("NV_Video_update", myConnection)) { myCommand.CommandType = CommandType.StoredProcedure; SqlParameter pID = new SqlParameter("@VideoID", SqlDbType.Int); pID.Value = model.VideoID; myCommand.Parameters.Add(pID); SqlParameter pTenVideo = new SqlParameter("@TenVideo", SqlDbType.NVarChar, 500); pTenVideo.Value = model.TenVideo; myCommand.Parameters.Add(pTenVideo); SqlParameter pDanhMuc = new SqlParameter("@DanhMuc", SqlDbType.Int); pDanhMuc.Value = model.DanhMuc; myCommand.Parameters.Add(pDanhMuc); SqlParameter pAnhMoTa = new SqlParameter("@ImageID", SqlDbType.Int); pAnhMoTa.Value = model.ImageID; myCommand.Parameters.Add(pAnhMoTa); SqlParameter pUrl = new SqlParameter("@Url", SqlDbType.NVarChar, 500); pUrl.Value = model.Url; myCommand.Parameters.Add(pUrl); SqlParameter pFileUpload = new SqlParameter("@FileUpload", SqlDbType.NVarChar, 300); pFileUpload.Value = model.FileUpload; myCommand.Parameters.Add(pFileUpload); try { myConnection.Open(); myCommand.ExecuteNonQuery(); return(true); } catch { return(false); } } } }