生成SQL语句分页的通用C#函数http://hi.baidu.com/lanxmail/blog/item/e5167f66cee44025aa184cba.html
来源:互联网 发布:python sip 安装 编辑:程序博客网 时间:2024/05/16 11:46
/// 生成取得记录总数的语句
/// </summary>
/// <param name="sql">原查询语句</param>
/// <returns>取得记录总数的语句</returns>
private string MakeRecordCountsSql(string sql)
{
string sqlGetRecordCounts = "select Count(*) from (" + sql + ") as TempTable";
return sqlGetRecordCounts;
}
/// <summary>
/// 生成分页查询语句
/// </summary>
/// <param name="sql">原查询语句</param>
/// <param name="orderField">用于分页排序的字段</param>
/// <param name="pageNumber">页码</param>
/// <param name="pageSize">页面记录数量</param>
/// <param name="recordCounts">记录总数</param>
/// <param name="pageCounts">页面总数</param>
/// <returns>分页查询语句</returns>
private string MakePagingSql(string sql, string orderField, int pageNumber, int pageSize, int recordCounts, out int pageCounts)
{
// 计算页面数量
if (Convert.ToInt32(pageNumber) < 1) pageNumber = 1;
if (Convert.ToInt32(pageSize) < 1) pageSize = 1;
pageCounts = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(recordCounts) / Convert.ToDouble(pageSize)));
string sqlQuery = "";
if (pageNumber == 1)
{
sqlQuery = "select top " + pageSize + " * from (" + sql + ") as TempTable order by " + orderField + " desc";
}
else
{
sqlQuery = "select top " + pageSize + " * from (" + sql + ") as TempTable where " + orderField + " < (select min(" + orderField + ") as MinID from ( select top " + (pageNumber - 1) * pageSize + " * from (" + sql + ") as MaxTempTable order by " + orderField + " desc) as MinTempTable) order by " + orderField + " desc";
}
return sqlQuery;
}
- 生成SQL语句分页的通用C#函数http://hi.baidu.com/lanxmail/blog/item/e5167f66cee44025aa184cba.html
- 动态SQL语句http://hi.baidu.com/lanxmail/blog/item/f46de417fbe5a508c83d6dac.html
- C#生成中文验证码http://hi.baidu.com/lanxmail/blog/item/280779e78eb27c2cb8382035.html
- 实现千万级数据分页的存储过程http://hi.baidu.com/lanxmail/blog/item/2820274632c8b0086a63e5a0.html
- asp.net利用多线程执行长时间的任务http://hi.baidu.com/lanxmail/blog/item/ccd6d5dcb8d65ea0cc1166a7.html
- net Framework 2.0 专门提供了配置文件的操作http://hi.baidu.com/lanxmail/blog/item/5fd8aa4439ff194d510ffe90.html
- 对.NET中导出数据到EXCEL的几种方法探讨[转]。http://hi.baidu.com/lanxmail/blog/item/82b3e1bf8608ca0b18d81f12.html
- SQL Server中动态执行SQL语句(转自:http://hi.baidu.com/senty/blog/item/5d6d36d3dc89a5073bf3cf3e.html)
- C# 静态构造函数详解(转自:http://hi.baidu.com/jiang_yy_jiang/blog/item/07d5cbe9ff6b4d32b90e2d5a.html)
- http://hi.baidu.com/heyg/blog/item/9ca8dcc4785706cb38db4937.html
- http://hi.baidu.com/suwey/blog/item/9b4d72c238e7e334e5dd3bc0.html
- http://hi.baidu.com/lhcling/blog/item/0e3e60cfa55aca3ef8dc61c0.html
- http://hi.baidu.com/jmugis/blog/item/ad03b11f89a25ef6e1fe0b18.html
- http://hi.baidu.com/nnffnn/blog/item/e84cd15c1d893943faf2c07c.html
- http://hi.baidu.com/herowzz/blog/item/286e3c546eb23157574e0077.html
- http://hi.baidu.com/kacaca/blog/item/1fd412d644f9f42907088b89.html
- http://hi.baidu.com/sophie198384/blog/item/26960501e9a757021d9583a0.html
- http://hi.baidu.com/123az/blog/item/f482f51980e8e04642a9ad6c.html
- 调研的内容 [原]
- Linux 2.4.x内核软中断机制-tasklet
- 1.1分页
- 什么是CSS hackhttp://blog.sina.com.cn/u/485cf1eb01000bni
- 在C#中编写多线程应用程序
- 生成SQL语句分页的通用C#函数http://hi.baidu.com/lanxmail/blog/item/e5167f66cee44025aa184cba.html
- hibernate v 3.2.4
- Oracle 11g 正式发布!
- Autoconf
- 冲杀职场的10只魔戒
- eclipse所有快捷键
- Tomcat6在JDK1.6下不能启动的解决
- 什么是CSS hack及写法。
- 新股民不能碰那些股票