• C#分页


    /// <summary>
               /// </summary>
                /// <param name="field">分页依据的字段(单表一般为主键)</param>
           /// <param name="sort">分页的排序规则</param>
           /// <param name="pageNo">页码</param>
           /// <param name="pageSize">每页条数</param>
          /// <param name="total">总记录数</param>
          /// <returns></returns>
           public DataSet UserTermInfo( string field,  string sort, int pageNo, int pageSize, out int total)
           {
             
               StringBuilder sbd = new StringBuilder(@"select a.*,b.DeptName from dbo.UserInfo a,dbo.Department b
                                  where a.deptID=b.deptID ");          

         string strSql = GetPagerSql(sbd.ToString(), field, sort, pageNo, pageSize);
               DataSet ds = SqlHelper.Instance.ExecSqlDataSet(strSql);
               total = Convert.ToInt32(ds.Tables[1].Rows[0][0]);
               return ds;
           }

    /// <summary>
           /// 获取分页的sql语句
           /// </summary>
           /// <param name="sql">分页前的查询sql语句</param>
           /// <param name="field">分页依据的字段(单表一般为主键)</param>
           /// <param name="sort">分页的排序规则</param>
           /// <param name="pageNo">页码</param>
           /// <param name="pageSize">每页数据条数</param>
           /// <returns>实现了分页功能的sql语句</returns>
           private static string GetPagerSql(string sql, string field, string sort, int pageNo, int pageSize)
           {
               return string.Format(
                   @"select * from (
                     select *,row_number() over (order by [{0}] {1}) __PagerRowNoField from (
                      {2}
                     ) s
                    ) t where __PagerRowNoField between {3} and {4};
                    select count(*) from ({2}) v",
               field, sort, sql, (pageNo - 1) * pageSize + 1, pageNo * pageSize);
           }

  • 相关阅读:
    小米手机刷开发版教程(超简单)
    Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]
    git常用命令
    SpringCloud Feign对Hystrix(断路由)的支持
    SpringCloud Feign使用详解
    SpringCloud高可用Eureka搭建
    springCloud Hystrix 断路由
    SpringBoot数据库连接池常用配置
    springBoot actuator监控配置及使用
    springCloud zuul网关服务
  • 原文地址:https://www.cnblogs.com/yf1019091807/p/5096296.html
Copyright © 2020-2023  润新知