日期:2014-05-17  浏览次数:20748 次

求datagridview分页代码
如题,我使用的数据库是sql2000,我不能改数据库,暂不能使用分页存储过程。
数据量在100W以上.有连接查询。
能不能单个SQL语句就搞定。2000没有ROW_NUMBER函数,貌似是用count?
急用。

------解决方案--------------------

绑定到 datagridview 在分页还是直接在数据库分页
------解决方案--------------------
http://www.cnblogs.com/kevin-top/archive/2010/01/05/1639448.html
我只会这个。。帮你找到代码。。这个符合你的要求不
------解决方案--------------------
http://blog.csdn.net/nileel/article/details/2509028
------解决方案--------------------
我只知道写查询语句的时候用top n,n是绑定数据的函数的一个变量。界面上有 上一页、下一页、转到、最后一页等等按钮,点击按钮执行绑定数据库的函数
------解决方案--------------------
SELECT TOP 页大小 *
FROM table1
WHERE id >
(
SELECT ISNULL(MAX(id),0) 
FROM 
(
SELECT TOP 页大小*(页数-1) id FROM table1 ORDER BY id
) A
)
ORDER BY id
------解决方案--------------------
我最近用的分页sql,不过一定要指定主键,top max分页效率还是挺不错的
C# code

        /// <summary>
        /// 生成top max分页sql语句,支持多表联查(事理)
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="fields">字段</param>
        /// <param name="primaryKey">主键</param>
        /// <param name="pageSize">一页显示多少条</param>
        /// <param name="currentPage">当前页数</param>
        /// <param name="where">where条件,无需加where</param>
        /// <param name="orderBy">order by条件,无需加order by</param>
        /// <returns>分页sql语句</returns>
        public static string GetDataPaginationSql(string tableName, string fields, string primaryKey,
            int pageSize, int currentPage, string where, string orderBy)
        {
            //SELECT TOP 10 UserId,AddUserId,Term,SchoolYear FROM SL_StudentsCQECDetail
            //WHERE CQECId >
            //(
            //    SELECT MAX(CQECId) FROM 
            //    (
            //        SELECT TOP 10 CQECId FROM SL_StudentsCQECDetail where UserId=479 ORDER BY CQECId
            //    ) AS T 
            //) 
            //and UserId=479
            //order by UserId

            if (currentPage > 0)
                currentPage--;

            StringBuilder sql = new StringBuilder();
            sql.Append("SELECT TOP " + pageSize + " " + fields + " FROM " + tableName);
            if (currentPage == 0)
            {
                if (!string.IsNullOrEmpty(where))
                    sql.Append(" WHERE " + where);
            }
            else
            {
                sql.Append(" WHERE " + primaryKey + ">");
                sql.Append("(SELECT MAX(" + primaryKey + ") FROM ");
                sql.Append("(SELECT TOP " + pageSize * currentPage + " " + primaryKey + " FROM " + tableName);
                if (!string.IsNullOrEmpty(where))
                    sql.Append(" WHERE " + where);
                sql.Append(" ORDER BY " + primaryKey + ") AS T)");
                if (!string.IsNullOrEmpty(where))
                    sql.Append(" AND " + where);
            }
            if (!string.IsNullOrEmpty(orderBy))
                sql.Append(" ORDER BY " + orderBy);
            return sql.ToString();
        }

------解决方案--------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;