我正在使用教育iSAMS软件生成报告,然后将该数据导出到Excel。几乎所有东西都是用经典ASP编写的,它是一个2帧的窗口,在左边框架上包含学生ID,在右边框架上包含每个学生ID的报告。单击左侧的学生,报告将显示在右侧窗格中。
报告使用学生ID作为参数:
paramBuilder.NextParameter(intID)
...这样可以正常工作并从SQL循环生成报告。
但是,我无法在Excel导出部分中使用该参数(我收到错误“语法错误或访问冲突”)。如果我从WHERE子句中删除参数,则导出有效(尽管它会导出所有学生ID,而不仅仅是导出的。)
我已经尝试了我能想到的一切,但我还是碰壁了。是否可以在导出中重复使用此参数?
提前致谢。
以下是代码:
<!--#include file="../../system/includes/inc_security.asp"-->
<!--#include file="../../system/includes/inc_theme.asp"-->
<% 'viewstudent-test.asp-v111-11-09-2017 --Includes Export to Excel
'txtModule="iSAMS_SCHOOLDIRECTORY"
'txtContext="SDSTUDENT"
intID = request.querystring("id")
%>
<!--- SHOW THE SUBJECT REPORTS --->
<table border="1px" width="100%">
<tr>
<td>Subject</td>
<td>Subject Report</td>
</tr>
<%
sql = "SELECT DISTINCT txtSchoolID, txtID, txtCommentID, txtComment FROM CAN_Tbl_UCAS_Reports WHERE intReportType = 1 AND txtSchoolID = " & paramBuilder.NextParameter(intID) & " ORDER BY txtID"
Set rsRecord = Database.GetRs(sql, conn, paramBuilder.Parameters)
if not rsRecord.EOF then
do until rsRecord.EOF
' First we need to create our Variables
SchoolID = rsRecord("txtSchoolID")
ConID = rsRecord("txtCommentID")
Com = rsRecord("txtComment")
%>
<tr>
<td style="text-align:center; vertical-align:top; height:10px"><%Response.Write(rsRecord.Fields("txtID").value)%></td>
<td style="text-align:center">
<form action="updateform.asp" method="post">
<input type="hidden" name="ID" value="<%=ConID%>" />
<input type="hidden" name="SchoolID" value="<%=SchoolID%>" />
<textarea rows="3" cols="180" name="comment"><%=Com%></textarea>
</form>
<td>
</tr>
<%
rsRecord.Movenext
loop
end if
rsRecord.close
set rsRecord = nothing
%>
</table>
<%If Request("ACT")="xls" Then
'Build & Execute Your SQL Command
SQL = "SELECT DISTINCT txtSchoolID, txtID, SubjectTeacher, txtComment FROM CAN_Tbl_UCAS_Reports WHERE intReportType = 1 AND txtSchoolID = '" & intID & "' ORDER BY txtID"
Set rstSearch = conn.Execute(SQL)
'Set the HTTP Header
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "filename=""Excel Export.xls"""
'Output Table %>
<table border="1" cellspacing="0" cellpadding="5">
<tr>
<th>Header 1</th><th>Header 2</th><th>Header 3</th>
</tr><% Do While Not rstSearch.EOF %>
<tr>
<td><%=rstSearch(1)%></td><td><%=rstSearch(3)%></td>
</tr>
<% rstSearch.MoveNext : Loop %>
</table>
<%
'Stop Processing Page Now
Response.End
End If
%>
<form action="?" method="post">
<input type="hidden" name="ACT" value="xls">
<input type="submit" value="Export To Excel">
</form>
</body>
</html>
<!--#include file="../../system/connections/inc_dbconnclose.asp"-->