《c#,gridview_datalist存储过程分页(效率高)》由会员分享,可在线阅读,更多相关《c#,gridview_datalist存储过程分页(效率高)(4页珍藏版)》请在金锄头文库上搜索。
1、C# GridView DataList 存储过程分页(效率高)2010-06-09 20:32:51 作者:佚名 来源: 浏览次数:0protected void bindlist() SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStringsNetconntiong.ConnectionString); SqlCommand command = new SqlCoprotected void bindlist()SqlConnection myConnection = new S
2、qlConnection(ConfigurationManager.ConnectionStringsNetconntiong.ConnectionString);SqlCommand command = new SqlCommand();/获取数据库连接字符串,生成新的数据库连接对象 .SqlCommand myCommand = new SqlCommand(Tech_SearchListzgbfwTion, myConnection);/标记数据库访问对象的命令类型为存储过程.myCommand.CommandType = CommandType.StoredProcedure;int
3、pageindex = 0;if (Request.QueryStringselectis = 1)key = Server.HtmlDecode(Request.QueryStringkeys);elsekey = ;/string strWhere = ;if (AspNetPager1.CurrentPageIndex (select maxset strOrder = order by + fldName + ascendif PageIndex = 1beginif strWhere != set strSQL = select top + str(PageSize) + + str
4、GetFields + from + tblName + where 1=1 + strWhere + key + + strOrderelseset strSQL = select top + str(PageSize) + + strGetFields + from + tblName + +strOrder-如果是第一页就执行以上代码,这样会加快执行速度endelsebegin-以下代码赋予了strSQL 以真正执行的 SQL 代码set strSQL = select top + str(PageSize) + + strGetFields + from + tblName + whe
5、re + fldName + + strTmp + (+ fldName + ) from (select top + str(PageIndex-1)*PageSize) + +fldName + from + tblName + + strOrder + ) as tblTmp) + strOrderif strWhere != set strSQL = select top + str(PageSize) + +strGetFields+ from + tblName + where +fldName + + strTmp + ( + fldName + ) from (select t
6、op + str(PageIndex-1)*PageSize) + +fldName + from + tblName + where 1=1 + strWhere + key + + strOrder + ) as tblTmp) and1=1 + strWhere + key + + strOrderendif strWhere != -得到记录的总行数set strSQL =strSQL+ ; select count(*) as Total from + tblName + where 1=1 + strWhere + keyelseset strSQL =strSQL+ ; select count(*) as Total from + tblName + endexec (strSQL)RETURNGO