Saving a dataset as a comma seperated values file.

  • Thread starter Thread starter Simon Verona
  • Start date Start date
S

Simon Verona

Hi,

This must be simple (I hope)! I've tried a google search but can't seem to
find what I want (probably using the wrong search keys!)

I'm trying to simply save a complete dataset as a CSV file so that it can be
easily opened up in Excel or emailed on.

Is there any simple way of doing this, or do I have to write code to scan
through the dataset and write it out line by line to a csv file?

Thanks in advance

Simon
 
Simon,

Scorpion(Kelly) has on his side a page to set it directly to an Excel file.

http://www.kjmsolutions.com/datasetarray.htm

I have this samplecode bellow what is queit generic to set a dataset
datatable to a csv file.

I hope this helps a little bit?

Cor

\\\
Dim sw As New IO.StreamWriter("C:\Whatever.csv")
For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
Dim row As New System.Text.StringBuilder
row.Append("""")
For y As Integer = 0 To ds.Tables(0).Columns.Count - 1
row.Append(ds.Tables(0).Rows(i)(y).tostring)
If y <> ds.Tables(0).Columns.Count - 1 Then
row.Append(""",""")
' if you want it with a tab
' row.Append("""")
' row.Append(chr(09))
' row.Append("""")
Else
row.Append("""")
End If
Next
sw.WriteLine(row.ToString)
Next
sw.Flush()
sw.Close()
///
 
Thanks Cor,

That is pretty much what I thought I would have to do ...

regards
Simon
 

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

Back
Top