在页面中显示数据库数据
<!--#include file="adovbs.inc"--><%
Set rs=Server.createObject("ADODB.RecordSet")
con="Provider=sqloledb;Data Source=PC-201006232001;Initial Catalog=www;User ID=sa;Password=; "
sql="select*form stdent order by no"
rs.Open sql,Con,AdOpenStatic,adlockreadonly,adcmdtext
rs.pageSize=4
Nowpage=Request("page")
If NowPage="" then NowPage=1
NowPage=CLng(NowPage)
If NowPage<1 then NowPage=1
If NowPage>rs.PageCount then NowPage=rs.PageCount
rs.AbsolutePage=NowPage
%>
<html>
<head><title>学生信息</title></head>
<body>
<div align="center">
<h3>学生信息表</h3>
<hr>
<table border="1">
<%'输出表头%>
<tr align=center valign=middle height=20>
<td><b>学号</b></td>
<td><b>姓名</b></td>
</tr>
<tr>
<%'输出当前页面记录
for i=0 to rs.pagesize-1
response.write"<tr align=center valign=middle>"
for i=0 to rs.fields.count-1
response.write"<td>"&rs.fields(i).value&" </td>"
next
response.write"</tr>"
rs.MoveNext
If rs.Eof then Exit For
next
response.write"</table><br>"
'输出第一页,上一页,和最后一页对应的超链
if nowpage<>1 then
response.write"<a href='selectpage.asp?page=1'>第一页</a>"
response.write" "; "
response.write"<a href='selectpage.asp? page="&noepage-1 &" '>上一页</a>"
end if
if nowpage<>rs.pagecount then
response.write" "
response.write"<a href='selectpage.asp? page="&nowpage+1 &" '>下一页</a>"
response.write" "
response.write"<a href='selectpage.asp?page="&rs.pagecount &" '>最后一页</a>"
end if
%>
<form action="selectpage.asp" method="post">
<p>共<% =rs.pagecount %>页 当前页;<% =nowpage %>
请输入页号;<input type="text" name="page" size=4>
<input type="reset" value="取消">
</p>
</form>
</div>
</body>
</html>
出现的错误如下所示:
错误类型:
Microsoft VBScript 编译器错误 (0x800A0410)
循环控制变量 'for' 无效
/ASP/selectpage.asp, line 31, column 5
for i=0 to rs.fields.count-1
----^