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         }

 


 

 

 

posted @ 2017-04-24 17:49  王小二不在家  阅读(329)  评论(0编辑  收藏  举报