zoukankan      html  css  js  c++  java
  • c#通过存储过程 out参数输出正常数据和count

     1 ALTER proc sp_loadlist
     2     (
     3     @pageIndexStart int ,
     4     @pageIndexEnd int,
     5     @total  int out
     6     )
     7 as 
     8 
     9 select [ID] ,[title] ,[content] ,[type]  ,[Date]  ,[people] ,[picUrl] from (select row_number()over(order by id)rownumber,* from [HKSJ_Main])a where rownumber between @pageIndexStart and @pageIndexEnd
    10 
    11 SELECT @total =COUNT (1) from [HKSJ_Main]

    1 int total = 0;
    2 MainInfoService mainList = new MainInfoService();
    3 
    4 //获取modellist
    5 MainListData = mainList.GetModelListByPage(pageIndexStart, pageIndexEnd,out total);
    6 
    //同时获取数据条数 7 int allCount = total;

     1 public static List<MainInfo> GetModelListByPageDal(int pageIndexStart, int pageIndexEnd, out int total)
     2         {
     3             DataTable dt = new DataTable();
     4             List<MainInfo> mainInfoList = new List<MainInfo>();
     5             
     6             //设定为输出参数
     7             SqlParameter totalParameter = new SqlParameter("@total", SqlDbType.Int);
     8             totalParameter.Direction = ParameterDirection.Output;
     9 
    10             SqlParameter[] parm = new SqlParameter[]{
    11                 new SqlParameter("@pageIndexStart",pageIndexStart),
    12                 new SqlParameter("@pageIndexEnd",pageIndexEnd), 
    13                 totalParameter
    14              };
    15              
    16             dt= SqlHelper.ExecuteDataTable("sp_loadlist", System.Data.CommandType.StoredProcedure, parm);
    17 
    18             for (int i = 0; i < dt.Rows.Count; i++)
    19             {
    20                 MainInfo mainItem = new MainInfo();
    21                 mainItem.ID=int.Parse( dt.Rows[i]["ID"].ToString());
    22                 mainItem.Title = dt.Rows[i]["title"].ToString();
    23                 mainItem.Content = dt.Rows[i]["content"].ToString();
    24                 mainItem.type = dt.Rows[i]["type"].ToString();
    25                 mainItem.Date = (DateTime)dt.Rows[i]["date"];
    26                 mainItem.People = dt.Rows[i]["people"].ToString();
    27                 mainInfoList.Add(mainItem);
    28             }
    29             //获取输出参数值
    30             total =(int) totalParameter.Value;
    31             return mainInfoList;
    32         }
    
    
    
     
  • 相关阅读:
    给力牛人
    设计模式
    微软真的要放弃Windows品牌吗?
    SQL2005 Express 自动安装之命令行
    SQL where之 in 在变量
    数据库求闭包,求最小函数依赖集,求候选码,判断模式分解是否为无损连接,3NF,BCNF
    别浪费了你的大内存[转]
    QQ空间免费养5级花和拥有人参果
    asp.net2 统一搜索引擎关键字编码[转]
    把网速提高4倍的方法和动画教程
  • 原文地址:https://www.cnblogs.com/allenzhang/p/6758093.html
Copyright © 2011-2022 走看看