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

    从数据库中直接导出取道泛型里面.
    命名空间:using System.Collections.Generic;

    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"]);
        }
    
     

  • 相关阅读:
    oracle-sql脚本
    vue生命周期
    使用vue搭建项目(创建手脚架)
    bootcss
    miniMobile(手机)
    mui(手机)
    layui
    Element
    如何学好Spring
    使用Vue做评论+localStorage存储(js模块化)
  • 原文地址:https://www.cnblogs.com/hulang/p/1917823.html
Copyright © 2011-2022 走看看