generate CSV or comma delimited

S

shank

What's the easiest way to generate CSV or a comma delimited file from an ASP
recordset? I've seen a few searching the internet and they appear to be
overkill or out of date.

thanks
 
R

Ray at

Something like:

Do while not rs.EOF
For each f in rs.fields
sOutput = sOutput & f.value & ","
Next
sOutput = sOutput & vbCrLf
Loop

Then write sOutput to a file using FSO. (If you're not sure about that,
post back.)

Not tested

Ray at work
 
S

shank

Do you happen to have some code example?
Beginning to end...?
The following code appears to be working, but no results.
thanks
 
P

Paul Hamlington

Hello

Try this:

Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set ctf = fs.CreateTextFile(Server.MapPath("test.csv"), 2)

If Not rset1.EOF Then
ctf.WriteLine("ISP,Address") '*** If you want titles to your columns
for your csv file

While Not rset1.EOF
ctf.WriteLine(""""&(rset1.Fields("ISP").Value)&""","""&(rset1.Fields("Address").Value)&"""")
rset1.movenext
Wend
End if

ctf.Close
Set fs=nothing

'**************************************
simple loops through your recordset writing out the fields on a line
with commas and creates new line per record, it will also put double
quote around all values, you will need to create a recordset, replace
my recordset tags with yours e.g. (rset1.Fields("ISP").Value), you
will also need to change the titles e.g. ("ISP,Address") to the titles
you want for each column.

CSV File Format should look something like: (using my recordset
fields)

ISP,Address
"ISP Name1","ISP Address1"
"ISP Name2","ISP Address2"

etc.

Hope this helps, I have quickly simplified code hope I haven't made
any mistakes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top