Solved

want  to download the DB data to CSV

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
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 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…

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