asp.net结合aspnetpager使用SQL2005的存储过程分页
更新时间:2009年07月18日 11:21:11 作者:
项目中用到了,同事阿春写了例子,并在实际项目中使用了,记录下。感谢春哥的无私奉献。
SQL2005的存储过程:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[P_GetPagedReCord]
(@startIndex INT, -- 开始索引号
@endindex INT, -- 结束索引号
@tblName varchar(255), -- 表名
@fldName varchar(255), -- 显示字段名
@OrderfldName varchar(255), -- 排序字段名
@IsReCount bit = 0, -- 返回记录总数, 非 0 值则返回
@OrderType bit = 0, -- 设置排序类型, 非 0 值则降序
@strWhere varchar(1000) = '' -- 查询条件 (注意: 不要加 where)
)
AS
declare @strSQL varchar(6000) -- 主语句
declare @strTmp varchar(100) -- 临时变量
declare @strOrder varchar(400) -- 排序类型
if @OrderType!=0
Begin
set @strOrder='Desc'
End
else
Begin
set @strOrder='Asc'
End
set @strSQL ='WITH orderList AS ( '+
'SELECT ROW_NUMBER() OVER (ORDER BY '+@OrderfldName+' '+@strOrder+')AS Row, '+@fldName+' '+
'from '+@tblName
if @strWhere!=''
set @strSQL = @strSQL+' where ' + @strWhere
set @strSQL=@strSQL+')'+
'SELECT '+@fldName+' '+
'FROM orderlist '+
'WHERE Row between '+str(@startIndex)+' and '+str(@endIndex)+''
if @IsReCount != 0
Begin
set @strSQL = ' select count(1) as Total from [' + @tblName + ']'
if @strWhere!=''
set @strSQL = @strSQL+' where ' + @strWhere
End
--print(@strSQL)
exec (@strSQL)
使用中的关键代码:
//翻页
protected void anpager_PageChanged(object sender, EventArgs e)
{
bind();
}
string strWhere = " 1 = 1 ";
ETHaiNan.BLL.ET_Video bll = new ETHaiNan.BLL.ET_Video();
this.anpager.RecordCount = int.Parse(bll.GetRecordCount(strWhere).Tables[0].Rows[0][0].ToString());
this.anpager.PageSize = 10;
this.anpager.AlwaysShow = true;
DataSet ds = bll.GetList(anpager.StartRecordIndex, anpager.EndRecordIndex,strWhere, 0);
this.rpt.DataSource = ds;
ds.Dispose();
数据访问层:
/// <summary>
/// 分页获取数据列表
/// </summary>
public DataSet GetList(int startIndex, int endindex, string strWhere, int IsReCount)
{
SqlParameter[] parameters = {
new SqlParameter("@startIndex", SqlDbType.Int),
new SqlParameter("@endindex", SqlDbType.Int),
new SqlParameter("@tblName", SqlDbType.VarChar, 255),
new SqlParameter("@fldName", SqlDbType.VarChar, 255),
new SqlParameter("@OrderfldName", SqlDbType.VarChar, 255),
new SqlParameter("@IsReCount", SqlDbType.Bit),
new SqlParameter("@OrderType", SqlDbType.Bit),
new SqlParameter("@strWhere", SqlDbType.VarChar,1000)
};
parameters[0].Value = startIndex;
parameters[1].Value = endindex;
parameters[2].Value = "ET_Video";
parameters[3].Value = "VideoID,Video_Name,Video_TypeID,Video_OrderCode,Video_Type,Video_AddDate";
parameters[4].Value = "VideoID";
parameters[5].Value = IsReCount;
parameters[6].Value = 1;
parameters[7].Value = strWhere;
return DbHelperSQL.RunProcedure("P_GetPagedReCord", parameters, "ds");
}
复制代码 代码如下:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[P_GetPagedReCord]
(@startIndex INT, -- 开始索引号
@endindex INT, -- 结束索引号
@tblName varchar(255), -- 表名
@fldName varchar(255), -- 显示字段名
@OrderfldName varchar(255), -- 排序字段名
@IsReCount bit = 0, -- 返回记录总数, 非 0 值则返回
@OrderType bit = 0, -- 设置排序类型, 非 0 值则降序
@strWhere varchar(1000) = '' -- 查询条件 (注意: 不要加 where)
)
AS
declare @strSQL varchar(6000) -- 主语句
declare @strTmp varchar(100) -- 临时变量
declare @strOrder varchar(400) -- 排序类型
if @OrderType!=0
Begin
set @strOrder='Desc'
End
else
Begin
set @strOrder='Asc'
End
set @strSQL ='WITH orderList AS ( '+
'SELECT ROW_NUMBER() OVER (ORDER BY '+@OrderfldName+' '+@strOrder+')AS Row, '+@fldName+' '+
'from '+@tblName
if @strWhere!=''
set @strSQL = @strSQL+' where ' + @strWhere
set @strSQL=@strSQL+')'+
'SELECT '+@fldName+' '+
'FROM orderlist '+
'WHERE Row between '+str(@startIndex)+' and '+str(@endIndex)+''
if @IsReCount != 0
Begin
set @strSQL = ' select count(1) as Total from [' + @tblName + ']'
if @strWhere!=''
set @strSQL = @strSQL+' where ' + @strWhere
End
--print(@strSQL)
exec (@strSQL)
使用中的关键代码:
复制代码 代码如下:
//翻页
protected void anpager_PageChanged(object sender, EventArgs e)
{
bind();
}
string strWhere = " 1 = 1 ";
ETHaiNan.BLL.ET_Video bll = new ETHaiNan.BLL.ET_Video();
this.anpager.RecordCount = int.Parse(bll.GetRecordCount(strWhere).Tables[0].Rows[0][0].ToString());
this.anpager.PageSize = 10;
this.anpager.AlwaysShow = true;
DataSet ds = bll.GetList(anpager.StartRecordIndex, anpager.EndRecordIndex,strWhere, 0);
this.rpt.DataSource = ds;
ds.Dispose();
数据访问层:
复制代码 代码如下:
/// <summary>
/// 分页获取数据列表
/// </summary>
public DataSet GetList(int startIndex, int endindex, string strWhere, int IsReCount)
{
SqlParameter[] parameters = {
new SqlParameter("@startIndex", SqlDbType.Int),
new SqlParameter("@endindex", SqlDbType.Int),
new SqlParameter("@tblName", SqlDbType.VarChar, 255),
new SqlParameter("@fldName", SqlDbType.VarChar, 255),
new SqlParameter("@OrderfldName", SqlDbType.VarChar, 255),
new SqlParameter("@IsReCount", SqlDbType.Bit),
new SqlParameter("@OrderType", SqlDbType.Bit),
new SqlParameter("@strWhere", SqlDbType.VarChar,1000)
};
parameters[0].Value = startIndex;
parameters[1].Value = endindex;
parameters[2].Value = "ET_Video";
parameters[3].Value = "VideoID,Video_Name,Video_TypeID,Video_OrderCode,Video_Type,Video_AddDate";
parameters[4].Value = "VideoID";
parameters[5].Value = IsReCount;
parameters[6].Value = 1;
parameters[7].Value = strWhere;
return DbHelperSQL.RunProcedure("P_GetPagedReCord", parameters, "ds");
}
您可能感兴趣的文章:
- asp.net中让Repeater和GridView支持DataPager分页
- Asp.Net数据控件引用AspNetPager.dll分页实现代码
- 分享一个asp.net pager分页控件
- asp.net分页控件AspNetPager的样式美化
- Asp.Net分页和AspNetPager控件的使用
- asp.net下Repeater使用 AspNetPager分页控件
- asp.net 通过aspnetpager为DataList分页
- AspNetAjaxPager,Asp.Net通用无刷新Ajax分页控件,支持多样式多数据绑定
- asp.net 分页sql语句(结合aspnetpager)
- asp.net mvc自定义pager封装与优化
相关文章
CZGL.ProcessMetrics处理监控数据的三种方式介绍
这篇文章介绍了CZGL.ProcessMetrics处理监控数据的三种方式,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2022-04-04
ASP.NET中实现jQuery Validation-Engine的Ajax验证实现代码
在jQuery的表变验证插件中Validation-Engine是一款高质量的产品,提示效果非常精美,而且里面包含了AJAX验证功能2012-05-05
看到本质而不是现象--解决ASP.NET CS0016的问题
看到本质而不是现象--解决ASP.NET CS0016的问题...2007-01-01
.NET 与树莓派WS28XX 灯带的颜色渐变动画效果的实现
所谓颜色渐变动画,首先,你要确定两种颜色——起始色和最终色,比如从绿色变成红色,绿色是起始,红色是终点。这篇文章主要介绍了.NET 与树莓派WS28XX 灯带的颜色渐变动画,需要的朋友可以参考下2021-12-12


最新评论