All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
SQL2000查询分析器中快捷键_mssql学习_编程技术
C#中正则表达式进行忽略大小写的字符串替换_.net资料_编程技术
asp.net(c#)如何把字符串转换成数组_[Asp.Net教程]
Email地址加密javascript版_JavaScript技术_编程技术
ASP.NET2.0中Treeview,的Checkboxes选中根枝叶全选中的实现方法_.net资料_编程技术
C#开发里List控件的使用方法介绍_[Asp.Net教程]
asp.net2.0动态加载主题
PHP+MySQL扎实基本功_php资料_编程技术
缓存技术详谈—php_[PHP教程]
.NET中加密与解密QueryString的方法_[Asp.Net教程]
Reading number is top 10 pictures
Poor doll, hand job was caught the currently in effect by his dad
Summer is most suitable for young people to travel in China6
The woman fight much more than men
Is said to be a Chinese female artist fame explicit pictures before1
超强高考作文
再发一张清纯美眉的照片
非常漂亮的泳装美女
日本小萝莉1
2015中美最新武器装备巅峰对决!
A man's favorite things12
Download software ranking
Unix video tutorial4
Sora aoi, the maid, students' uniforms
apache-tomcat-6.0.33
C++教程第四版
美女写真3
Boxer's Top ten classic battle9
Sora aoi, the nurse, uniform ,nursing assistant
少妇苏霞全本
Ashlynn Video1
C#高级编程(第4版)
归海一刀 published in(发表于) 2014/1/30 1:27:07 Edit(编辑)
datareader显示很快的分页程序实例_[Asp.Net教程]

datareader显示很快的分页程序实例_[Asp.Net教程]

datareader显示很快的分页程序实例_[Asp.Net教程]
1.用DataReader分页 (显示很快)

///

/// PageList for DataReader
///

///
///
///
///
///
///
///
///
public DataTable PageListReader(string connectionString, string sql, int pageSize, int curPage, out int pageCount, out int count, params DbParameter[] cmdParms)
{
int first = 0;
int last = 0;
int fieldCount = 0;
using (SqlConnection conn = new SqlConnection(connectionString))
{
SqlCommand cmd = conn.CreateCommand();
PRepareCommand(cmd, conn, null, CommandType.Text, sql, cmdParms);
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
DataTable dt = new DataTable();
fieldCount = reader.FieldCount;
for (int i = 0; i < fieldCount; i++)
{
DataColumn col = new DataColumn();
col.ColumnName = reader.GetName(i);
col.DataType = reader.GetFieldType(i);
dt.Columns.Add(col);
}
count = 0;
first = (curPage - 1) * pageSize+1;
last = curPage * pageSize;
while (reader.Read())
{
count++;
if (count >= first && last >= count)
{
DataRow r = dt.NewRow();
for (int i = 0; i < fieldCount; i++)
{
r[i] = reader[i];
}
dt.Rows.Add(r);
}
}
reader.Close();
pageCount = Convert.ToInt32(Math.Ceiling((double)count / (double)pageSize));
return dt;
}
}


2.用ROW_NUMBER()分页

///

/// 分页获取数据(Sql Server 2005) for ROW_NUMBER()
///

/// 数据库链接
/// 获取数据集的Sql
/// 排序字段,可以多个
/// 每页显示多少条
/// 当前页码
/// 总页数
/// 总记录数
///DbParameter
/// DataTable
public DataTable PageList(string connectionString, string sql, string fldSort, int pageSize, int curPage, out int pageCount, out int count, params DbParameter[] cmdParms)
{
StringBuilder strSql = new StringBuilder();
strSql.AppendFormat(@"SELECT count(0) from {0} as MyTableCount;
select * from (
SELECT ROW_NUMBER() OVER(order by {1}) RowNumber,*
from {0} mytable
) mytable2
where RowNumber between {2} and {3}"
, sql, fldSort, Convert.ToString((curPage - 1) * pageSize + 1), Convert.ToString((curPage * pageSize)));

DataSet ds = ExecuteQuery(connectionString, CommandType.Text, strSql.ToString(), cmdParms);
count = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
pageCount = Convert.ToInt32(Math.Ceiling((double)count / (double)pageSize));
return ds.Tables[1];
}
来源:http://www.shilicn.com http://www.dzdq8.com


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.