Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP output to CSV file

Posted on 2003-10-21
1
Medium Priority
?
177 Views
Last Modified: 2010-03-25
I have an ASP page that returns the results from a database search.  It used to work but I noticed recently that the CSV file now displays the html code from the ASP page rather than the results from the search.  Any suggestions on how to correct this problem?  I checked to make sure the IIS 4.0 App Mappings associates the .csv file with asp.dll and it does.  Thanks for your help!

This is the code I'm using:

<%response.ContentType="application/CSV"%>
<%Response.AddHeader "Content-Disposition", "filename=filename.csv;"%>

<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=windows-1252">
<title>Search Results</title>
</head>

<body>

<%
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.open "MyConnection","",""
   
   
 sql = "SELECT * FROM Table1"

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, conn ', 3, 3
%>


<TABLE BORDER=1>
<TR>
    <TD><B>Field1</B></TD>
    <TD><B>Field2</B></TD>
        </TR>
    <% Do while Not RS.EOF %>
    <TR>
     <TD VALIGN=TOP><% = RS("Field1") %>&nbsp;</TD>  
    <TD VALIGN=TOP><% = RS("Field2") %>&nbsp;</TD>
          </TR>
 <%   RS.MoveNext
      Loop   %>
    </TABLE>

<%rs.close
set rs=nothing
conn.close
set conn=nothing
%>

</body>
</html>

0
Comment
Question by:drees727
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
sicknote earned 500 total points
ID: 9593407
try this:

<%
response.ContentType="application/CSV"

Response.AddHeader "Content-Disposition", "filename=filename.csv;"

Set conn = Server.CreateObject("ADODB.Connection")
conn.open "MyConnection","",""

sql = "SELECT * FROM Table1"

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, conn ', 3, 3

Do while Not RS.EOF
      Response.Write(RS("Field1"))
      Response.Write(",")
      Response.Write(RS("Field2"))
      Response.Write(vbCr)
      RS.MoveNext
Loop

rs.close
set rs=nothing
conn.close
set conn=nothing
%>
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question