Potresti creare un file CSV (separati da virgola)
dove la prima riga viene interpretata come il nome dei campi e dalla seconda in poi ci sono i valori
io uso sempre una funzione di questo tipo:
codice:
Function SaveCSV(ByRef Rs,Filename)
On Error Resume Next
Dim k
k = 0
For Each campo In RS.Fields
if k = 0 then
Intestazione = F.Name
else
Intestazione = Intestazione & ", " & F.Name
k = k + 1
Next
Intestazione = Intestazione & vbcrlf
Contenuto = RS.GetString(, , ", ", vbCrLf, "")
Contenuto = Left(Contenuto,Len(Contenuto)-2)
Set Fso = Server.CreateObject("Scripting.FilesystemObject")
Set ObjFile = Fso.OpenFile(Server.MapPath(Filename),2,true)
ObjFile.write(Intestazione & Contenuto)
ObjFile.Close
Set ObjFile = nothing
if err.Number > 0 then SaveCSV = false else SaveCsv = true
End Function
In questo modo basta un
codice:
<%
Rs.Open "Select primocampo,secondocampo,terzocampo",Connection
%>
....
<% if SaveCSV("/Export/esportazioneData.csv",Rs) then %>
scarica
<% end if %>
come vedi con un for each leggo i nomi dei campi per la prima riga
e poi con un getstring stampo il contenuto ( e ci levo l'ultima virgola), dopo di che con un oggetto FSO salvo il file
Occhio che se estrai anche dei campi memo potresti avere dei problemi (se contengono virgole o ritorni a capo)
a quel punto ti scorri il recordset e dopo che hai fatto le dovute sostituzioni scrivi nel file con il metodo writeLine invece che write
ed alla fine del loop lo chiudi
codice:
Set ObjFile = Fso.OpenFile(Server.MapPath(Filename),2,true) k = 0
For Each campo In RS.Fields
if k = 0 then
Intestazione = F.Name
else
Intestazione = Intestazione & ", " & F.Name
k = k + 1
Next
Intestazione = Intestazione & vbcrlf
objFile.writeLine Intestazione
while not rs.eof
' Esegui tutti i replace
objFile.writeLine Rs("primoCampo") & "," Rs("secondoCampo") .....
rs.movenext
Wend
objFile.Close