コード例 #1
0
ファイル: DanhMucMedia.cs プロジェクト: BuiDucDinh/QuanLyHoSo
        public NV_DanhMuc_ChiTiet GetById(int id)
        {
            using (SqlConnection myConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("NV_DanhMuc_getByID", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    SqlParameter pID = new SqlParameter("@id", SqlDbType.Int);
                    pID.Value = id;
                    myCommand.Parameters.Add(pID);

                    NV_DanhMuc_ChiTiet model = new NV_DanhMuc_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.DanhMucID  = id;
                        model.TenDanhMuc = dt.Rows[0]["TenDanhMuc"].ToString();
                        model.DanhMucCha = int.Parse(dt.Rows[0]["DanhMucCha"].ToString());
                        model.MoTa       = dt.Rows[0]["MoTa"].ToString();
                        model.TheLoai    = int.Parse(dt.Rows[0]["TheLoai"].ToString());
                    }
                    return(model);
                }
            }
        }
コード例 #2
0
ファイル: DanhMucMedia.cs プロジェクト: BuiDucDinh/QuanLyHoSo
        public bool update(NV_DanhMuc_ChiTiet model)
        {
            using (SqlConnection myConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("NV_Danhmuc_update", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    SqlParameter pID = new SqlParameter("@DanhMucID", SqlDbType.Int);
                    pID.Value = model.DanhMucID;
                    myCommand.Parameters.Add(pID);

                    SqlParameter pTenDanhMuc = new SqlParameter("@TenDanhMuc", SqlDbType.NVarChar, 200);
                    pTenDanhMuc.Value = model.TenDanhMuc;
                    myCommand.Parameters.Add(pTenDanhMuc);

                    SqlParameter pDanhMucCha = new SqlParameter("@DanhMucCha", SqlDbType.Int);
                    pDanhMucCha.Value = model.DanhMucCha;
                    myCommand.Parameters.Add(pDanhMucCha);

                    SqlParameter pMoTa = new SqlParameter("@MoTa", SqlDbType.NText);
                    pMoTa.Value = model.MoTa;
                    myCommand.Parameters.Add(pMoTa);

                    SqlParameter pTheLoai = new SqlParameter("@TheLoai", SqlDbType.Int);
                    pTheLoai.Value = model.TheLoai;
                    myCommand.Parameters.Add(pTheLoai);
                    try
                    {
                        myConnection.Open();
                        myCommand.ExecuteNonQuery();
                        return(true);
                    }
                    catch
                    {
                        return(false);
                    }
                }
            }
        }