Exemplo n.º 1
0
 /// <summary>
 /// 初始化数据
 /// </summary>
 /// <param name="row">DataTable行</param>
 /// <param name="newsINfo">新闻对象</param>
 private void LoadEntity(DataRow row, NewsInfo newsINfo)
 {
     newsINfo.NewsId     = Convert.ToInt32(row["NewsId"]);
     newsINfo.NewsConent = row["NewsConent"].ToString();
     newsINfo.RegTime    = Convert.ToDateTime(row["RegTime"]);
     newsINfo.TypeId     = Convert.ToInt32(row["TypeId"]);
 }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            NewsInfoDal newInfoDal = new NewsInfoDal();
            NewsInfo    newsInfo   = new NewsInfo();

            newsInfo.NewsConent = textBox1.Text;
            newsInfo.RegTime    = DateTime.Now;
            newsInfo.TypeId     = Convert.ToInt32(comboBox1.SelectedValue);
            newInfoDal.InsertNews(newsInfo);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 添加一条新闻数据
        /// </summary>
        /// <param name="newsInfo">新闻对象</param>
        /// <returns></returns>
        public int InsertNews(NewsInfo newsInfo)
        {
            //NewsId, NewsConent, RegTime, TypeId
            string sql = "Insert into NewsInfo values(@NewsConent, @RegTime, @TypeId)";

            SqlParameter[] pars =
            {
                new SqlParameter("@NewsConent", SqlDbType.NVarChar),
                new SqlParameter("@RegTime",    SqlDbType.DateTime),
                new SqlParameter("@TypeId",     SqlDbType.Int)
            };
            pars[0].Value = newsInfo.NewsConent;
            pars[1].Value = newsInfo.RegTime;
            pars[2].Value = newsInfo.TypeId;
            return(SqlHeper.EntityNunQuery(sql, CommandType.Text, pars));
        }
Exemplo n.º 4
0
        /// <summary>
        /// 查询所有数据
        /// </summary>
        /// <returns></returns>
        public List <NewsInfo> GetNewsList()
        {
            string          Sql   = "select * from NewsInfo";
            DataTable       table = SqlHeper.GetEntityList(Sql, CommandType.Text);
            List <NewsInfo> list  = null;

            if (table.Rows.Count > 0)
            {
                list = new List <NewsInfo>();
                NewsInfo newsINfo = null;
                foreach (DataRow row in table.Rows)
                {
                    newsINfo = new NewsInfo();
                    LoadEntity(row, newsINfo);
                    list.Add(newsINfo);
                }
            }
            return(list);
        }