我正在构建一个页面来显示一系列记录,但希望按位置过滤结果,并在自己的子标题下显示结果记录。
所有记录都在一个db表中,并且总共有2个查询。
SQL1 doest在我的第二个HTML上有任何值
<html>
<head>
<title>Top Five Movies booking</title>
<style>
body {
font: 100% "Courier New", Courier, monospace;
}
table {
/* The default setting is border-collapse: separate;. By changing separate to collapse as shown below, the space between each table cell is removed. */
border-collapse: collapse;
}
caption {
font-size: .9125em;
font-weight: bold;
margin-bottom: .5em;
}
th,
td {
font-size: .875em;
padding: .5em .75em;
}
td {
border: 1px solid #000;
}
</style>
</head>
<body>
<p>
<%
'declare the variables
Dim Connection
Dim ConnString
Dim rs
Dim SQL
'define the connection string, specify database driver
ConnString="Driver={SQL Server};Server=10.1.12.6;Database=VISTAIT;Uid=sa;Pwd=Cxx1234;"
'declare the SQL statement that will query the database
SQL = "SELECT top 5 (OrderTH_strMovieName) as Top5HotFilms,Convert(char(8), OrderTH_dtmSessionDateTime, 112) as DayOfCount,count( OrderTH_strMovieName)as filmoccurence FROM [VISTAIT].[dbo].[tblOrderTicketHistory] where Convert(char(8), OrderTH_dtmSessionDateTime, 112) >= (SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))) GROuP BY OrderTH_strMovieName , Convert(char(8), OrderTH_dtmSessionDateTime, 112)ORDER BY filmoccurence desc"
SQL1 = "SELECT top 10 (OrderTH_strMovieName) as Top5HotFilms,Convert(char(8), OrderTH_dtmSessionDateTime, 112) as DayOfCount,count( OrderTH_strMovieName)as filmoccurence FROM [VISTAIT].[dbo].[tblOrderTicketHistory] where Convert(char(8), OrderTH_dtmSessionDateTime, 112) >= (SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))) GROuP BY OrderTH_strMovieName , Convert(char(8), OrderTH_dtmSessionDateTime, 112)ORDER BY filmoccurence desc"
'create an instance of the ADO connection and rs objects
Set Connection = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.RecordSet")
Set rs1 = Server.CreateObject("ADODB.RecordSet")
'Open the connection to the database
Connection.Open ConnString
'Open the rs object executing the SQL statement and return records
rs.Open SQL, Connection
'first of all determine whether there are any records
If rs.EOF Then
Response.Write("No records returned.")
Else
'if there are records then loop through the fields
Dim HTML, pHTML
Dim field1, field2, field3, field4
Set field1 = RS("Top5HotFilms")
Set field2 = RS("DayOfCount")
Set field3 = RS("filmoccurence")
HTML = "<table CellPadding=0 CellSpacing=0 border=1><caption>Top Five Movies booking</caption><TR><TD>Booking Date</td><TD>Day</td><TD>Occurence</td></TR>"&vbCrLf
Do While Not rs.EOF
pHTML = "<TR>"
pHTML = pHTML & "<TD> " & field1 & "</TD>"
pHTML = pHTML & "<TD> " & field2 & "</TD>"
pHTML = pHTML & "<TD> " & field3 & "</TD>"
pHTML = pHTML & "</TR>" & vbCrLf
HTML = HTML & pHTML
rs.MoveNext
Loop
HTML = HTML & "</table>" & vbCrLf
Response.Write HTML
End If
rs1.Open SQL1, Connection
If rs1.EOF Then
Response.Write("No records returned.")
Else
'if there are records then loop through the fields
Dim HTML1, pHTML1
Dim field5, field6, field7, field8
Set field5 = RS1("Top5HotFilms")
Set field6 = RS1("DayOfCount")
Set field7 = RS1("filmoccurence")
HTML1 = "<table CellPadding=0 CellSpacing=0 border=1><caption>Top Ten Movies booking</caption><TR><TD>Booking Date</td><TD>Day</td><TD>Occurence</td></TR>"&vbCrLf
Do While Not rs.EOF
pHTML1 = "<TR>"
pHTML1 = pHTML1 & "<TD> " & field5 & "</TD>"
pHTML1 = pHTML1 & "<TD> " & field6 & "</TD>"
pHTML1 = pHTML1 & "<TD> " & field7 & "</TD>"
pHTML1 = pHTML1 & "</TR>" & vbCrLf
HTML1 = HTML1 & pHTML1
rs.MoveNext
Loop
HTML1 = HTML1 & "</table>" & vbCrLf
Response.Write HTML1
End If
'close the connection and rs objects to free up resources
rs.Close
Set rs=nothing
rs1.Close
Set rs1=nothing
Connection.Close
Set Connection=nothing
%>
</body>
</html>
答案 0 :(得分:0)
SQL1部分包含 rs.movenext
和 Do While Not rs.EOF
,而不是 rs1.movenext
和 Do While Not rs1.EOF
强>
以下是第二部分的正确代码
rs1.Open SQL1, Connection
If rs1.EOF Then
Response.Write("No records returned.")
Else
'if there are records then loop through the fields
Dim HTML1, pHTML1
Dim field5, field6, field7, field8
HTML1 = "<table CellPadding=0 CellSpacing=0 border=1><caption>Top Ten Movies booking</caption><TR><TD>Booking Date</td><TD>Day</td><TD>Occurence</td></TR>"&vbCrLf
Do While Not rs1.EOF
Set field5 = RS1("Top5HotFilms")
Set field6 = RS1("DayOfCount")
Set field7 = RS1("filmoccurence")
pHTML1 = "<TR>"
pHTML1 = pHTML1 & "<TD> " & field5 & "</TD>"
pHTML1 = pHTML1 & "<TD> " & field6 & "</TD>"
pHTML1 = pHTML1 & "<TD> " & field7 & "</TD>"
pHTML1 = pHTML1 & "</TR>" & vbCrLf
HTML1 = HTML1 & pHTML1
rs1.MoveNext
Loop
HTML1 = HTML1 & "</table>" & vbCrLf
Response.Write HTML1
End If