Solved

want  to download the DB data to CSV

Posted on 2004-09-20
5
252 Views
Last Modified: 2010-04-03
I want to download a data fetched from an SQL Query to a CSV file.
I am working in ASP. I have also written the code but the problem is that along with the Data the whole HTML page is getting dumped into the CSV file. I want only the DB data and not the whole page. The Page should remain as it is. Please help. I am pasting the code which I have written. The code also forces a save download dialogbox.
Thanks Nilanjan

Code Begins ***************
************************
if operation = "DOWNLOAD" then
            strSQL = "SELECT * FROM GOST_NINSYOU"
            
            if fn_createRecordSet(objRecSet) = false then ' calling function to create recordset
                  Response.Redirect("Error.asp")
            end if
            call fn_rsSQL(objConn,strSQL,objRecSet) ' calling funtion to populate recordset
                  
            For Each F In objRecSet.Fields ' Filling the table field names
              Head = Head & ", " & F.Name
            Next
            Head = Mid(Head,3) & vbCrLf
            Response.Buffer = TRUE
            Response.Clear
            'Response.ContentType = "application/octet-stream"  '****This line give error (Dont know why?????)'
            Response.AddHeader "Content-Disposition", "attachment;filename=" & "test.csv"
            Response.Write Head
            Response.Write objRecSet.GetString(,,", ",vbCrLf,"")
            Response.Expires = 0
            Response.Flush()                  
                        
            call fn_deleteRecordSet(objRecSet) ' calling function to clear recordset
end if
0
Comment
Question by:nilanjan02
5 Comments
 
LVL 2

Expert Comment

by:mingz
Comment Utility
Maybe you can try other var name beside "Head"..
The page may have taken the html head instead, just a suggestion.
0
 

Author Comment

by:nilanjan02
Comment Utility
Thanks for the comment, but i have got he solution.
I need to use Response.End() to stop writing into the CSV file
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
Comment Utility
Question answered by asker or dialog valuable.
Closed, 125 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Admin
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

We wanted to provide an in-depth explanation of the Ping Node offering clarifications on its function and usage. Incorrect Ping Node configuration and functionality can cause problems with HA clusters. The importance of this article is critical for …
Problem description :  Some external hard disks / USB flash drives do not show actual space as mentioned in the factory settings. This is a common problem when you use an 8 GB USB drive to make it bootable to install a firmware/ driver on a serv…
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…
This Micro Tutorial will teach you how to reformat your flash drive. Sometimes your flash drive may have issues carrying files so this will completely restore it to manufacturing settings. Make sure to backup all files before reformatting. This w…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now