2014-11-06 133 views
-1

我有一個.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%> 
+0

爲什麼在進行一次數據庫調用時進行嵌套的重複數據庫調用? '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

+0

感謝您的提示。我會研究它! – user2403260 2014-11-07 04:42:14

回答

1

位猜測的在這裏,但嘗試有在一個單一的代碼塊的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