public NV_Quangcao_ChiTiet GetById(int id) { using (SqlConnection myConnection = new SqlConnection(ConnectionString)) { using (SqlCommand myCommand = new SqlCommand("NV_Quangcao_getByID", myConnection)) { myCommand.CommandType = CommandType.StoredProcedure; SqlParameter pID = new SqlParameter("@ID", SqlDbType.Int); pID.Value = id; myCommand.Parameters.Add(pID); DataTable dt; NV_Quangcao_ChiTiet model = new NV_Quangcao_ChiTiet(); myConnection.Open(); using (SqlDataAdapter mData = new SqlDataAdapter(myCommand)) { dt = new DataTable(); mData.Fill(dt); } if (dt != null && dt.Rows.Count > 0) { model = new NV_Quangcao_ChiTiet(dt); } return(model); } } }
public bool update(NV_Quangcao_ChiTiet model) { using (SqlConnection myConnection = new SqlConnection(ConnectionString)) { using (SqlCommand myCommand = new SqlCommand("NV_Quangcao_update", myConnection)) { myCommand.CommandType = CommandType.StoredProcedure; SqlParameter pID = new SqlParameter("@ID", SqlDbType.Int); pID.Value = model.ID; myCommand.Parameters.Add(pID); SqlParameter pName = new SqlParameter("@Name", SqlDbType.NVarChar, 250); pName.Value = model.Name; myCommand.Parameters.Add(pName); SqlParameter pType = new SqlParameter("@Type", SqlDbType.Int); pType.Value = model.Type; myCommand.Parameters.Add(pType); SqlParameter pMenuID = new SqlParameter("@MenuID", SqlDbType.Int); pMenuID.Value = model.MenuID; myCommand.Parameters.Add(pMenuID); SqlParameter pLink = new SqlParameter("@Link", SqlDbType.NVarChar, 250); pLink.Value = model.Link; myCommand.Parameters.Add(pLink); SqlParameter pDescription = new SqlParameter("@Description", SqlDbType.NText); pDescription.Value = model.Description; myCommand.Parameters.Add(pDescription); SqlParameter pDuyet = new SqlParameter("@Duyet", SqlDbType.Bit); pDuyet.Value = model.Duyet; myCommand.Parameters.Add(pDuyet); SqlParameter pIsImage = new SqlParameter("@IsImage", SqlDbType.Bit); pIsImage.Value = model.IsImage; myCommand.Parameters.Add(pIsImage); SqlParameter pImageID = new SqlParameter("@ImageID", SqlDbType.Int); pImageID.Value = model.ImageID; myCommand.Parameters.Add(pImageID); SqlParameter pTarget = new SqlParameter("@Target", SqlDbType.NVarChar, 50); pTarget.Value = model.Target; myCommand.Parameters.Add(pTarget); SqlParameter pStt = new SqlParameter("@Stt", SqlDbType.Int); pStt.Value = model.Stt; myCommand.Parameters.Add(pStt); try { myConnection.Open(); myCommand.ExecuteNonQuery(); return(true); } catch { return(false); } } } }