Solved

want  to download the DB data to CSV

Posted on 2004-09-20
5
255 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
[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
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

How to update Firmware and Bios in Dell Equalogic PS6000 Arrays and Hard Disks firmware update.
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
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…

726 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