Пример #1
0
        public bool them(NV_Image_ChiTiet model)
        {
            using (SqlConnection myConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("NV_Image_add", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    SqlParameter pTenAnh = new SqlParameter("@TenAnh", SqlDbType.NVarChar, 300);
                    pTenAnh.Value = model.TenAnh;
                    myCommand.Parameters.Add(pTenAnh);

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

                    SqlParameter pNgayTao = new SqlParameter("@NgayTao", SqlDbType.DateTime);
                    pNgayTao.Value = model.NgayTao;
                    myCommand.Parameters.Add(pNgayTao);

                    try
                    {
                        myConnection.Open();
                        myCommand.ExecuteNonQuery();
                        return(true);
                    }
                    catch
                    {
                        return(false);
                    }
                }
            }
        }
Пример #2
0
        public NV_Image_ChiTiet GetById(int id)
        {
            using (SqlConnection myConnection = new SqlConnection(ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("NV_Image_getByID", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

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

                    NV_Image_ChiTiet model = new NV_Image_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.ImageID = id;
                        model.TenAnh  = dt.Rows[0]["TenAnh"].ToString();
                        model.NgayTao = Convert.ToDateTime(dt.Rows[0]["NgayTao"].ToString());
                        model.DanhMuc = int.Parse(dt.Rows[0]["DanhMuc"].ToString());
                    }
                    return(model);
                }
            }
        }