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         }
    
    
    
     
  • 相关阅读:
    Redis 常用命令整理
    TCP系列01—概述及协议头格式
    TCP/IP详解--TCP网络传输数据包1460MSS和1448负载
    TCP中报文段大小(MSS)、MTU
    DNS 过滤脚本
    TCP SYN Cookies – DDoS defence
    python virtualenv venv 虚拟环境
    git 命令总结
    王兴三横四纵
    获取国税门户可供下载的资源文档
  • 原文地址:https://www.cnblogs.com/allenzhang/p/6758093.html
Copyright © 2011-2022 走看看