asp程序出错!
我是想利用asp将access查询结果导出到excel文件,出错,请指点,谢谢。代码如下程序代码:
<!-- #include file = "../common/site.inc" --> <% Dim rsAdministrator Set rsAdministrator = cn.Execute("SELECT * FROM Administrator WHERE AdministratorID = '" & Session("AdminID") & "' AND Password = '" & Session("AdminPwd") & "'") If rsAdministrator.EOF = True And rsAdministrator.BOF = True Then Response.Redirect "logon.asp" End If rsAdministrator.Close Set rsAdministrator = Nothing %> <% Dim rs Set rs = cn.Execute("select * from outks") if not (rs.eof And rs.bof) then dim ttxt,file,filepath,writefile ttxt="kscj.xls" '为要写入的文件取个文件名,后缀可以是txt,xls,这里我用csv,这种文件打开也是excel表 Set file = CreateObject("Scripting.FileSystemObject") Application.lock filepath=Server.MapPath(ttxt) Set Writefile = file.CreateTextFile(filepath,true) Writefile.WriteLine "学号,姓名,考试分数,考试项目" do while not rs.eof Writefile.WriteLine rs("StudentID")&","&rs("Student_Name")&","&rs("ReportScore")&","&rs("Experiment_Name")&" rs.movenext loop Writefile.close Application.unlock rs.close set rs=nothing end if Response.Write "生成EXCEL文件成功,点击<a href=""kscj.xls"" target=""_blank"">下载</a>!" rstData.Close set rstData = nothing Conn.Close Set Conn = nothing Function DataToRsStatic(Conn,strSql) Dim RsStatic Set DataToRsStatic = Nothing If Conn Is Nothing Then Exit Function End If Set RsStatic = CreateObject("ADODB.RecordSet") RsStatic.CursorLocation = 3 RsStatic.Open strSql,Conn,3,3 If Err.Number <> 0 Then Exit Function End If Set DataToRsStatic = RsStatic End Function %>
[ 本帖最后由 wwm123456789 于 2013-6-15 22:14 编辑 ]