将以前写的SQL2分查找法通用分页存储过程算法 改…
2008-02-22 09:42:32来源:互联网 阅读 ()
![新老客户大回馈,云服务器低至5折](/info/templets/default/images/760x90_D.jpg)
using System;
namespace CountryPark.DAL
...{
/**//**//**//// <summary>
/// PageList 的摘要说明。
/// </summary>
public sealed class PageList
...{
static PageList()
...{
}
/**//**//**//// <summary>
/// 分页查询数据记录总数获取
/// </summary>
/// <param name="_tbName">----要显示的表或多个表的连接</param>
/// <param name="_ID">----主表的主键</param>
/// <param name="_strCondition">----查询条件,不需where</param>
/// <param name="_Dist">----是否添加查询字段的 DISTINCT 默认0不添加/1添加</param>
/// <returns></returns>
public static string getPageListCounts(string _tbName, string _ID, string _strCondition, int _Dist)
...{
//---存放取得查询结果总数的查询语句
//---对含有DISTINCT的查询进行SQL构造
//---对含有DISTINCT的总数查询进行SQL构造
string strTmp="", SqlSelect="", SqlCounts="";
if (_Dist == 0)
...{
SqlSelect = "SELECT ";
SqlCounts = "COUNT(*)";
}
else
...{
SqlSelect = "SELECT DISTINCT ";
SqlCounts = "COUNT(DISTINCT " _ID ")";
}
if (_strCondition == string.Empty)
...{
strTmp = SqlSelect " @Counts=" SqlCounts " FROM " _tbName;
}
else
...{
strTmp = SqlSelect " @Counts=" SqlCounts " FROM " " WHERE (1=1) " _strCondition;
}
return strTmp;
}
/**//**//**//// <summary>
/// 获取分页数据查询SQL
/// </summary>
/// <param name="_tbName">----要显示的表或多个表的连接</param>
/// <param name="_fldName">----要显示的字段列表</param>
/// <param name="_PageSize">----每页显示的记录个数</param>
/// <param name="_Page">----要显示那一页的记录</param>
/// <param name="_PageCount">----查询结果分页后的总页数</param>
/// <param name="_Counts">----查询到的记录数</param>
/// <param name="_fldSort">----排序字段列表或条件(如果是多字段排列Sort指代最后一个排序字段的排列顺序(最后一个排序字段不加排序标记)--程序传参如:' SortA Asc,SortB Desc,SortC ')</param>
/// <param name="_Sort">----排序方法,0为升序,1为降序</param>
/// <param name="_strCondition">----查询条件,不需where</param>
/// <param name="_ID">----主表的主键</param>
/// <param name="_Dist">----是否添加查询字段的 DISTINCT 默认0不添加/1添加</param>
/// <returns></returns>
public static string getPageListSql(string _tbName, string _fldName, int _PageSize, int _Page, out int _PageCount, int _Counts, string _fldSort, int _Sort, string _strCondition, string _ID, int _Dist)
...{
string strTmp=""; //---strTmp用于返回的SQL语句
string SqlSelect="", strSortType="", strFSortType="";
if (_Dist == 0)
...{
SqlSelect = "SELECT ";
}
else
...{
SqlSelect = "SELECT DISTINCT ";
}
if (_Sort == 0)
...{
strFSortType = " ASC";
strSortType = " DESC";
}
else
...{
strFSortType = " DESC";
strSortType = " ASC";
}
// ----取得查询结果总数量-----
int tmpCounts = 1;
if (_Counts != 0)
...{
tmpCounts = _Counts;
}
// --取得分页总数
_PageCount = (tmpCounts _PageSize - 1)/_PageSize;
// /**//**当前页大于总页数 取最后一页**/
if (_Page > _PageCount)
...{
_Page = _PageCount;
}
if (_Page <= 0)
...{
_Page = 1;
}
// --/*-----数据分页2分处理-------*/
int pageIndex = tmpCounts/_PageSize;
int lastCount = tmpCounts%_PageSize;
if (lastCount > 0)
...{
pageIndex = pageIndex 1;
}
else
...{
lastCount = _PageSize;
}
if (_strCondition == string.Empty) // --没有设置显示条件
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash