Solved

want  to download the DB data to CSV

Posted on 2004-09-20
5
253 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
ID: 12110094
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
ID: 12120565
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
ID: 12433324
Question answered by asker or dialog valuable.
Closed, 125 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Admin
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

AWS Glacier is Amazons cheapest storage option and is their answer to a ‘Cold’ storage service.  Customers primarily use this service for archival purposes and storage of infrastructure backups.  Its unlimited storage potential and low storage cost …
This article is an update and follow-up of my previous article:   Storage 101: common concepts in the IT enterprise storage This time, I expand on more frequently used storage concepts.
This video teaches viewers how to encrypt an external drive that requires a password to read and edit the drive. All tasks are done in Disk Utility. Plug in the external drive you wish to encrypt: Make sure all previous data on the drive has been …
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now