欢迎来到天天文库
浏览记录
ID:34726848
大小:69.18 KB
页数:5页
时间:2019-03-10
《visualstudio2005中gridview手动分页自定义分页》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、1.创建存储过程,数据库为MicrosoftSQLServer2000,useNorthwindgoselect*fromOrdersgoifexists(select*fromsysobjectswherename='proc_ordersinfo'andtype='P') dropprocedureproc_ordersinfogo--创建查询表Orders的存储过程,@PageIndex页面索引(页面索引=当前页数-1),@PageSize每页显示数据的多少(多少行)--@PageCount页面总数,@RecordCount表中的记录总数createproced
2、ureproc_ordersinfo @PageIndexint, @PageSizeint, @PageCountintoutas declare@RecordCountint,@strsqlnvarchar(1000)select@RecordCount=count(*)fromordersset@PageCount=ceiling(@RecordCount*1.0/@PageSize)--第1种情况,表只够分成一页if@PageIndex=0or@PageCount<=1 set@strsql=N'selecttop'+str(@PageSize)+'*from
3、OrdersorderbyOrderIDdesc'--第2种情况,要查询表的最后一页(可看作表Orders已被分成几个页了)elseif@PageIndex=@PageCount-1 set@strsql=N'select *from(selecttop'+str(@RecordCount-@PageIndex*@PageSize)+'*fromOrdersorderbyOrderIDasc)TempTableorderbyOrderIDdesc'--第3种情况,查询非表的最后一页else set@strsql=N'selecttop'+str(@PageSize)+
4、'*from(selecttop'+str(@RecordCount-@PageIndex*@PageSize)+'*fromOrdersorderbyOrderIDasc)TempTableorderbyOrderIDdesc'--执行SQL语句exec(@strsql)go 2.创建显示数据的方法 classCConnDB里的方法returnConn()返回数据库连接usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Web;usingSystem.Web.Securi
5、ty;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;//导入需要使用的命名空间usingSystem.Data.SqlClient;//////CConnDB的摘要说明///publicclassCConnDB{ publicCConnDB() { // //TODO:在此处添加构造函数逻辑 // } publicSqlCon
6、nectionreturnConn(){ SqlConnectionsconn=newSqlConnection("server=.;database=Northwind;uid=sa;pwd=sa"); returnsconn; }} classCDisplayOdersInfo里的方法DisplayOrdersInfo()返回一个DataSetusingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Web;usingSystem.Web.Sec
7、urity;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;//导入需要使用的命名空间usingSystem.Data.SqlClient;//////CDisplayOdersInfo的摘要说明///publicclassCDisplayOdersInfo{ CConnDBccdb=newCConnDB();
此文档下载收益归作者所有