码迷,mamicode.com
首页 > 数据库 > 详细

分页sql

时间:2015-01-04 15:02:54      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:

 /// <summary>
        /// 根据页数分页
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <param name="where"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        public static DataSet GetListByPage(int page, int pagesize, string where, string column)
        {
            System.Text.StringBuilder sbu5 = new StringBuilder();
            int num1 = (page - 1) * pagesize;
            int num2 = page * pagesize;
            sbu5.Append("select " + column);
            sbu5.Append(" FROM(");
            sbu5.Append("SELECT A.*, ROWNUM RN FROM (SELECT * FROM tabel WHERE 1=1" + where + ") A WHERE 1=1" + where + " AND ROWNUM <= " + num2);
            sbu5.Append(")");
            sbu5.Append("where RN >" + num1);
            return DbHelperOra.Query(sbu5.ToString());
        }

        /// <summary>
        ///  获得数据列表
        /// </summary>
        /// <param name="strWhere"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        public static DataSet GetList(string strWhere, string column)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select " + column);
            strSql.Append(" FROM table");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where 1=1 " + strWhere);
            }
            return DbHelperOra.Query(strSql.ToString());
        }

  

分页sql

标签:

原文地址:http://www.cnblogs.com/myblogslh/p/4200958.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!