使用List<T>

.aspx页面中的方法:

//将获取到的List<T>值赋值给TextBox

private void InitTextBox()

{

    int id = int.Parse(ViewState["ID"].ToString());
            List<NewsModel> list =NewsBLL.GetLoad(id);
            foreach (NewsModel m in list)
            {
                txtTitle.Text = m.Title;
                txtCata.Text = m.NewsCatagory;
                txtContent.Text = m.Content;
                listBoxAttachment.Items.Add(m.Attachment);
            }

}

 

BLL中调用DAL中的方法:

/// <summary>
        /// 获取新闻所有信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static List<NewsModel> GetLoad(int id)
        {
            string sql = "select * from TB_XWGG where ID="+id;
            return NewsHelper.GetList(sql);
        }

 

DAL中方法:

/// <summary>
        /// 返回新闻表中的所有信息
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static List<NewsModel> GetList(string sql)
        {
            List<NewsModel> list = new List<NewsModel>();
            NewsModel m = new NewsModel();
            try
            {
                OraConn = new OracleConnection(ConnString);
                OraCmd = OraConn.CreateCommand();
                OraCmd.CommandText = sql;
                OraConn.Open();
                OracleDataReader reader = OraCmd.ExecuteReader();
                while (reader.Read())
                {
                    m.ID = int.Parse(reader["ID"].ToString());
                    m.Title = reader["BT"].ToString();  //标题
                    m.Content = reader["NR"].ToString();  //内容
                    m.NewsCatagory = reader["XWLX"].ToString();  //新闻类型
                    m.Creator = reader["FBR"].ToString();  //发布人
                    m.CreateUnitID = reader["FBDW"].ToString();  //发布单位
                    m.CreateTime = Convert.ToDateTime(reader["FBSJ"].ToString());   //发布时间
                    m.Attachment = reader["FJMC"].ToString();    //附件名称
                    m.AttachmentPath=reader["FJLJ"].ToString();   //附件路径
                    m.AttachmentState=int.Parse(reader["FJCZ"].ToString());   //附件状态
                    m.NewsState=int.Parse(reader["SFQY"].ToString());  //新闻状态
                }
                list.Add(m);
            }
            catch (Exception)
            { }
            finally {
                OraCmd.Dispose(); //释放资源
                OraConn.Close();  //关闭数据库
            }
            return list;
        }

posted @ 2012-06-18 11:36  jsping68  阅读(936)  评论(0编辑  收藏  举报