zoukankan      html  css  js  c++  java
  • 泛型与SqlDataReader

    从数据库中直接导出取道泛型里面.

    public static List<News> GetTopNews(int NewsKindId,int IntTop)
        
    {
            List<News> AllNews = new List<News>();
            string procname = "dbo.GetTopNews";
            SqlParameter[] prams 
    =new SqlParameter("@NewsKindId", SqlDbType.Int),
                                    
    new SqlParameter("@IntTop", SqlDbType.Int)}
    ;
            prams[
    0].Value = NewsKindId;
            prams[
    1].Value = IntTop;
            SqlDataReader Dr 
    = DataBase.RunProcGetReader(procname,prams);
            
    while (Dr.Read())
            
    {
                AllNews.Add(new News(Dr));


            }

            Dr.Close();
            
    return AllNews;
        }

    在News类中:
        public News(SqlDataReader Dr)
        
    {
            
    this._newsid = Convert.ToInt32(Dr["NewsId"]);
            
    this._newstitle = Convert.ToString(Dr["NewsTitle"]);
            
    this._newsbody = Convert.ToString(Dr["NewsBody"]);
            
    this._newskindid = Convert.ToInt32(Dr["NewsKindId"]);
            
    this._userid = Convert.ToInt32(Dr["UserId"]);
            
    this._pubdate = Convert.ToDateTime(Dr["PubDate"]);
        }
  • 相关阅读:
    【转载】Linux的进程间通信-信号量
    【转载】高性能数据库连接池的内幕
    【转载】我是一块硬盘(下)
    【转载】我是一块硬盘(上)
    69. Sqrt(x)
    68. Text Justification
    67. Add Binary
    66. Plus One
    65. Valid Number
    64. Minimum Path Sum
  • 原文地址:https://www.cnblogs.com/whitetiger/p/1055690.html
Copyright © 2011-2022 走看看