API-DAL层调用分页(有分页的dal)

/// <summary>
        /// 分页存储过程的调用
        /// </summary>
        /// <param name="pageCount"></param>
        /// <param name="name"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public List<AskBillModel> GetList(out int pageCount,string name="",int pageIndex=1,int pageSize=0)
        {
            SqlParameter[] paras = new SqlParameter[] {
                //ParameterName是指定存储过程的参数名,SqlDbType指定的是存储过程里面参数的类型,SqlValue是给该参数赋值
                new SqlParameter(){ ParameterName="@Name", SqlDbType=SqlDbType.NVarChar,SqlValue=name },
                new SqlParameter(){ ParameterName="@PageIndex", SqlDbType=SqlDbType.Int,SqlValue=pageIndex },
                new SqlParameter(){ ParameterName="@PageSize", SqlDbType=SqlDbType.Int,SqlValue=pageSize },
                //Direction是指定参数的输入输出类型,Output代表输出参数,输出参数不需要给value值
                new SqlParameter(){ ParameterName="@PageCount", SqlDbType=SqlDbType.Int,Direction=ParameterDirection.Output }
            };

            var list = DBHelper.GetListByProc<AskBillModel>("Proc_Paged", paras);
            //一定要在执行了存储过程之后  再给输出的参数赋值
            pageCount = Convert.ToInt32(paras[3].Value);  //得到总页数
            return list;
        }
posted @ 2020-06-09 20:42  G蠢蠢  阅读(172)  评论(0编辑  收藏  举报