zoukankan      html  css  js  c++  java
  • C# ado.net 使用 row_number over() 简单的分页示例

            /// <summary>
            /// 获取Paging列表
            /// </summary>
            public List<HousesAgentEntity> GetPageList(int pageIndex, int pageSize, out int amount, string where)
            {
                int count = 0; //总页数
    
                string sqlCount = "Select Count(*) From HousesAgent" + where;//根据条件计算总页数
    
                List<HousesAgentEntity> list = new List<HousesAgentEntity>();
    
                #region 组装分页的sql语句 
                           
                string sql = string.Format(@"Select * From ( Select Row_Number() Over(Order By UserId desc) Rows, * From HousesAgent {0} ) tb Where Rows > @Begin And Rows <= @End", where);  
    
                SqlParameter[] parameters = {
                new SqlParameter("@Begin", (pageIndex-1) * pageSize),
                new SqlParameter("@End", pageIndex * pageSize)
                };
    
                #endregion
    
    
                try
                {
    
                    SqlDataReader dr = SqlSimpleHelper.ExecuteReader(SqlSimpleHelper.ConnectionString, CommandType.Text, sql, parameters);
                    list = DataReaderToList(dr);
    
                    Object obj = SqlSimpleHelper.ExecuteScalar(SqlSimpleHelper.ConnectionString, CommandType.Text, sqlCount);
                    if (obj != null)
                    {
                        int.TryParse(obj.ToString(), out count);
                    }
                    amount = count;
                }
    
                catch (Exception ex)
                {
                    //记录异常日志
                    LogHelper.WriteErrorLog(GetErrorMethod("GetPageList"), ex.Message);
                    amount = 0;
                }
                return list;
            }
    

      

  • 相关阅读:
    青蛙学Linux—软件安装
    青蛙学Linux—文本编辑器Vi/Vim
    linux下安装java
    anaconda 换源
    origin从图中获得数据
    endnote X7参考文献缩进设置
    endnote X7 加入文献
    endnote X7使用方法
    linux下安装openmpi
    origin添加error bar
  • 原文地址:https://www.cnblogs.com/sunqiang/p/6109268.html
Copyright © 2011-2022 走看看