经典的ASP导出为CSV生成空白第一行
问题描述:
我有一个.asp页面,它使用来自mysql数据库的数据生成一个csv文件来下载。我的问题是,生成的csv文件的第一行是空白的。如何消除输出中的空白第一行?经典的ASP导出为CSV生成空白第一行
<%Response.Buffer = True
Response.Clear
Response.ContentType = "text/csv"
Response.AddHeader "Content-Disposition", "attachment;filename=export.csv"
struserid=Request.QueryString("uid")
set con = Server.CreateObject("ADODB.Connection")
%>
<!--#INCLUDE FILE="databaseconnection.asp"-->
<%Con.open DSNtest
set rec1=con.execute ("SELECT * FROM orders where receivedp = '0000-00-00 00:00:00' AND pid = '" & struserid & "' order by zipid asc")%>
sep=;
Address;City;State;Zip;
<%while not rec1.eof
strzipid = rec1("zipid")
set rec3=con.execute ("SELECT * FROM zip where zipcode = '" & strzipid & "'")
%>
<%=rec1("address")%>;<%=rec3("city")%>;<%=rec3("state")%>;<%=rec3("zipcode")%>;
<%rec1.movenext
wend
rec1.close
set rec1 = nothing
rec3.close
set rec3 = nothing
con.close
set con = Nothing%>
答
位猜测的在这里,但尝试有在一个单一的代码块的VBS并用vbcrlf添加在您需要的换行符 - 即
<% Con.open DSNtest
set rec1=con.execute ("SELECT * FROM orders where receivedp = '0000-00-00 00:00:00' AND pid = '" & struserid & "' order by zipid asc")
Response.write "sep=;" & vbcrlf
Response.write "Address;City;State;Zip;" & vbcrlf
while not rec1.eof
strzipid = rec1("zipid")
set rec3=con.execute ("SELECT * FROM zip where zipcode = '" & strzipid & "'")
Response.write rec1("address")&";"&rec3("city")&";"&rec3("state")&";"&rec3("zipcode") & vbcrlf
rec1.movenext
wend
'etc
闭幕的ASP代码块并在下一行开始一个新行添加额外的行
+0
非常感谢,工作! – user2403260 2014-11-07 04:42:44
为什么在进行一次数据库调用时进行嵌套的重复数据库调用? 'SELECT * from orders AS o INNER JOIN zip AS z ON o.zipid = z.zipcode WHERE o.receivedp ='0000-00-00 00:00:00'AND o.pid ='“&struserid&”'order通过o.zipid asc'。阅读JOINS:http://dev.mysql.com/doc/refman/5.0/en/join.html – 2014-11-07 00:49:12
感谢您的提示。我会研究它! – user2403260 2014-11-07 04:42:14