记录集分页不起作用
Recordset Paging isn't Working
谁能告诉我为什么我的记录集分页不起作用。我对这些东西知之甚少,我从这个微软网站 link: http://support.microsoft.com/kb/202125
提取的代码中的部分内容
这是我的代码:
Dim con, con2, rec, rec2, dsn, dsn2, sql, sql2, rName, sDate, eDate, intPageCount
rName=Request.Form("rn")
sDate=FormatDateTime(Request.Form("sD"), 2)
eDate=FormatDateTime(Request.Form("eD"), 2)
dsn = "Radio"
dsn2 = "InfoLib_SQL"
sql = "SELECT * FROM T_RadioControlLog WHERE RadioName = '"&rName&"' AND CONVERT(date, Date, 101) >=
CONVERT(date, '"&sDate&"', 101) AND CONVERT(date, Date, 101) <= CONVERT(date, '"&eDate&"', 101)"
set con=Server.CreateObject("ADODB.Connection")
set rec=Server.CreateObject("ADODB.Recordset")
rec.CursorLocation=3
con.Open dsn, "pw", "pw"
rec.Open sql, con
rec.PageSize=5
intPageCount=rec.PageCount
Select Case Request("Action")
case "<<"
intpage =1
case"<"
intpage = Request("intpage")-1
if intpage < 1 then intpage = 1
case ">"
intpage = Request("intpage")+1
if intpage > intPageCount then intpage = intPageCount
case ">>"
intpage = intPageCount
case else
intpage = 1
end select
If NOT rec.eof Then
Response.write("<table>")
rec.AbsolutePage = intpage
For intRecord = 1 to rec.PageSize
Response.write("<tr><td>Radio Name</td><td>Date</td><td>Employee Name</td><td>ID#</td></tr>")
Response.write("<tr><td>" & rec.fields("RadioName") & "</td>")
Response.Write("<td>" & rec.fields("Date") & "</td>")
set con2=Server.CreateObject("ADODB.Connection")
set rec2=Server.CreateObject("ADODB.Recordset")
sql2 = "SELECT EMP_NA FROM EMP_TABLE WHERE ID='"&rec.fields("ID#")&"'"
con2.Open dsn2, "pw", "pw"
rec2.Open sql2, con2
Response.Write("<td>" & rec2.fields("EMP") & "</td>")
Response.Write("<td>" & rec.fields("ID#")& "</td></tr>")
rec.movenext
rec2.close
con2.close
set rec2=nothing
set con2=nothing
If rec.EOF Then Exit For
Next
%>
<tr>
<form name="pageNav" action="results.asp" method="post">
<input type="hidden" name="intpage" value="<%=intpage%>">
<input type="submit" name="Action" value="<<">
<input type="submit" name="Action" value="<">
<input type="submit" name="Action" value=">">
<input type="submit" name="Action" value=">>">
Page: <%=intpage & " of " & intPageCount%>
</tr>
</form>
</table>
<%
Else
Response.write("Sorry, no entries were found.")
End If
rec.close
set rec=nothing
con.close
set con=nothing
对数据库工作和条目的调用明确地 returned,我得到一个小的 table,其中有 5 个条目,因为我的记录集设置为 return,但是当我单击>>, <, >, etc.
它没有显示任何内容,页面只是空白。如果有人可以解释记录集分页的工作原理,那就太好了。
Function ShowFolderList(folderspec)
Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
s = s & f1.name
s = s & "<BR>"
Next
ShowFolderList = s
End Function
这来自帮助。 FSO 中没有通配符。你必须自己做。所以测试 f1.name
是否满足您的要求,然后复制该文件。
关于您的方法的几点评论。
你Dim
不过intPageCount
不过intPage
没什么大不了的不过还是个人喜好你应该Dim
吧。
您在回发期间似乎没有保存前几页的字段。具体我看这段代码
rName=Request.Form("rn")
sDate=FormatDateTime(Request.Form("sD"), 2)
eDate=FormatDateTime(Request.Form("eD"), 2)
但没有这样的对应部分
<form name="pageNav" action="results.asp" method="post">
<input type="hidden" name="rn" value="<%=rName%>">
<input type="hidden" name="sD" value="<%=sDate%>">
<input type="hidden" name="eD" value="<%=eDate%>">
<input type="hidden" name="intpage" value="<%=intpage%>">
在回发时为这些值启用回调。
谁能告诉我为什么我的记录集分页不起作用。我对这些东西知之甚少,我从这个微软网站 link: http://support.microsoft.com/kb/202125
提取的代码中的部分内容这是我的代码:
Dim con, con2, rec, rec2, dsn, dsn2, sql, sql2, rName, sDate, eDate, intPageCount
rName=Request.Form("rn")
sDate=FormatDateTime(Request.Form("sD"), 2)
eDate=FormatDateTime(Request.Form("eD"), 2)
dsn = "Radio"
dsn2 = "InfoLib_SQL"
sql = "SELECT * FROM T_RadioControlLog WHERE RadioName = '"&rName&"' AND CONVERT(date, Date, 101) >=
CONVERT(date, '"&sDate&"', 101) AND CONVERT(date, Date, 101) <= CONVERT(date, '"&eDate&"', 101)"
set con=Server.CreateObject("ADODB.Connection")
set rec=Server.CreateObject("ADODB.Recordset")
rec.CursorLocation=3
con.Open dsn, "pw", "pw"
rec.Open sql, con
rec.PageSize=5
intPageCount=rec.PageCount
Select Case Request("Action")
case "<<"
intpage =1
case"<"
intpage = Request("intpage")-1
if intpage < 1 then intpage = 1
case ">"
intpage = Request("intpage")+1
if intpage > intPageCount then intpage = intPageCount
case ">>"
intpage = intPageCount
case else
intpage = 1
end select
If NOT rec.eof Then
Response.write("<table>")
rec.AbsolutePage = intpage
For intRecord = 1 to rec.PageSize
Response.write("<tr><td>Radio Name</td><td>Date</td><td>Employee Name</td><td>ID#</td></tr>")
Response.write("<tr><td>" & rec.fields("RadioName") & "</td>")
Response.Write("<td>" & rec.fields("Date") & "</td>")
set con2=Server.CreateObject("ADODB.Connection")
set rec2=Server.CreateObject("ADODB.Recordset")
sql2 = "SELECT EMP_NA FROM EMP_TABLE WHERE ID='"&rec.fields("ID#")&"'"
con2.Open dsn2, "pw", "pw"
rec2.Open sql2, con2
Response.Write("<td>" & rec2.fields("EMP") & "</td>")
Response.Write("<td>" & rec.fields("ID#")& "</td></tr>")
rec.movenext
rec2.close
con2.close
set rec2=nothing
set con2=nothing
If rec.EOF Then Exit For
Next
%>
<tr>
<form name="pageNav" action="results.asp" method="post">
<input type="hidden" name="intpage" value="<%=intpage%>">
<input type="submit" name="Action" value="<<">
<input type="submit" name="Action" value="<">
<input type="submit" name="Action" value=">">
<input type="submit" name="Action" value=">>">
Page: <%=intpage & " of " & intPageCount%>
</tr>
</form>
</table>
<%
Else
Response.write("Sorry, no entries were found.")
End If
rec.close
set rec=nothing
con.close
set con=nothing
对数据库工作和条目的调用明确地 returned,我得到一个小的 table,其中有 5 个条目,因为我的记录集设置为 return,但是当我单击>>, <, >, etc.
它没有显示任何内容,页面只是空白。如果有人可以解释记录集分页的工作原理,那就太好了。
Function ShowFolderList(folderspec)
Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
s = s & f1.name
s = s & "<BR>"
Next
ShowFolderList = s
End Function
这来自帮助。 FSO 中没有通配符。你必须自己做。所以测试 f1.name
是否满足您的要求,然后复制该文件。
关于您的方法的几点评论。
你Dim
不过intPageCount
不过intPage
没什么大不了的不过还是个人喜好你应该Dim
吧。
您在回发期间似乎没有保存前几页的字段。具体我看这段代码
rName=Request.Form("rn")
sDate=FormatDateTime(Request.Form("sD"), 2)
eDate=FormatDateTime(Request.Form("eD"), 2)
但没有这样的对应部分
<form name="pageNav" action="results.asp" method="post">
<input type="hidden" name="rn" value="<%=rName%>">
<input type="hidden" name="sD" value="<%=sDate%>">
<input type="hidden" name="eD" value="<%=eDate%>">
<input type="hidden" name="intpage" value="<%=intpage%>">
在回发时为这些值启用回调。