/// <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)); }
/// <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); }