WEB开发网
开发学院WEB开发ASP 优秀的百万级数据分页存储过程代码(ver2.0) 阅读

优秀的百万级数据分页存储过程代码(ver2.0)

 2008-08-31 12:53:24 来源:WEB开发网   
核心提示:'以下代码为网页代码Response.Buffer = TrueDim SqlLocalName,SqlUsername,SqlPassword,SqlDatabaseNameDim ConnStr,Conn ''''''''''&
'----------------------------------------以下代码为网页代码

Response.Buffer = True
Dim SqlLocalName,SqlUsername,SqlPassword,SqlDatabaseName
Dim ConnStr,Conn

'''''''''''''''''''''''''''''''''SQL数据库 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SqlLocalName ="(local)" '连接IP [ 本地用 (local) 外地用IP ]
SqlUsername ="sa" '数据库用户名
SqlPassword ="XXXXXX" '用户密码
SqlDatabaseName="NewsTable" '数据库名
ConnStr = "Provider=Sqloledb;User ID=" & SqlUsername & "; Password=" & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source=" & SqlLocalName & ";"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
On Error Resume Next
Set Conn=Server.CreateObject("ADODB.Connection")
Conn.open ConnStr

If Err Then
  err.Clear
Set Conn = Nothing
Response.Write "<div style='font-size:14px;color=#ff0000' align='center'>数据库连接出错,请检查数据库连接字串</div>"
Response.End
End If

'本类进行实例化代码,不将所有可能性条件分页考虑进去。本类仅作参考
'--------------------------------------------------------------------------------------------

'PageNo-当前页;PageSizeX-分页大小;PageCountX-总页数;FieldCount-总记录数;StrWhere-查询条件
Dim PageNo,PageSizeX,PageCountX,FieldCount,StrWhere

'进行赋值
PageNo=trim(Request.Querystring("PageNo"))

PageSizeX=30 '定义分页大小
if isnumeric(PageNo) or PageNo="" then '如果没有Page值,进行初始化值
PageNo=abs(PageNo)
if PageNo=0 then PageNo=1
else
PageNo=1
end if

StrWhere="(ClassCode=0101 and Hits>20)" '注意,此处注意字符的长度

set recom = server.createobject("adodb.command")
recom.activeconnection = Conn
recom.commandtype = 4

recom.commandtext = "News_Class"
recom.Parameters.Append recom.CreateParameter("@StrWhere",202,1,100,StrWhere)
recom.Parameters.Append recom.CreateParameter("@PageSize",3,1,,PageSizeX)
recom.Parameters.Append recom.CreateParameter("@PageIndex",3,1,,PageNo)

set rs = recom.execute ()

if rs.eof then
  set rs=nothing : set recom=nothing : Conn.Close : set Conn=nothing
response.write "<script LANGUAGE='javascript'>alert('当前没有找到任何记录,请返回重新操作!');history.go(-1);</script>"
response.end
end if

'显示数据
do while not rs.eof
response.write ""&rs("Title")&"  添加时间:"&rs("AddTime")&"<br/>"
rs.movenext
loop

'取得记录总数,计算页数
set rs = rs.NextRecordset
if rs("countx") > 0 then
FieldCount=rs( "countx")
else
FieldCount=0
end if

if (FieldCount mod PageSizeX)>0 then
  PageCountX=((FieldCount - (FieldCount mod PageSizeX))/ PageSizeX)+1
else
PageCountX= (FieldCount / PageSizeX)
end if

'进行关闭和释放相关资源
set rs=nothing : set recom=nothing : Conn.Close : set Conn=nothing

'显示分页
if PageNo<=1 then
Response.Write "<font color='#FF0000'>[首页] [上一页]</font>"
else
Response.Write "[<a href='?PageNo=1' target='_self' title='首页'><font color='#FF0000'>首页</font></a>] "
Response.Write "[<a href='?PageNo="&(PageNo-1)&"' target='_self' title='上一页'><font color='#FF0000'>上一页</font></a>] "
end if

上一页 下一页

Tags:优秀 百万 数据

编辑录入:coldstar [复制链接] [打 印]
赞助商链接