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(objRecS
et) = false then ' calling function to create recordset
Response.Redirect("Error.a
sp")
end if
call fn_rsSQL(objConn,strSQL,ob
jRecSet) ' 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(objRecS
et) ' calling function to clear recordset
end if
Start Free Trial