Dataset to CSV file

G

Guest

Hi
Looking for a fast way to convert a Dataset from a web service into a
"filename.csv" file.

Right now I am looping thur the dataset.
///
Dim myDataTable As DataTable = ds.Tables(0)
If (myDataTable.Columns.Count <> 0) Then
For Each column As DataColumn In myDataTable.Columns
sb.Append(column.ColumnName & ",")
Next
sb.Append(vbCrLf)
For Each row In myDataTable.Rows
For Each column As DataColumn In myDataTable.Columns
sb.Append(row(column).ToString() & ",")
Next
sb.Append(vbCrLf)
Next
End If
///
Looking for a better way.

Thanks
BrianDH
 
C

Cor Ligthert [MVP]

Brian

I thought that this is a good method, what is bad with it, remember that
behind the scene something the same will happen as well (If you change your
method in a way that it does not write the last comma, which needs only an
extra test to check if the column is not the last column and than placing
the comma.)

However I thought that I had seen that Paul had a method that it could be
done using OleDB. Therefore I searched the newsgroups on DataSet CSV Paul

This gives a bunch of answers.
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&q=dataset+csv+paul&qt_s=Search

Maybe you can check this answers as long as Paul has not answered you
himself.
Be aware that where he tells that it does not work in the first answer
Dataset to CSV that is talked about updating a csv file.

I hope this gives some help,

Cor
 
P

Paul Clement

¤ Brian
¤
¤ I thought that this is a good method, what is bad with it, remember that
¤ behind the scene something the same will happen as well (If you change your
¤ method in a way that it does not write the last comma, which needs only an
¤ extra test to check if the column is not the last column and than placing
¤ the comma.)
¤
¤ However I thought that I had seen that Paul had a method that it could be
¤ done using OleDB. Therefore I searched the newsgroups on DataSet CSV Paul
¤
¤ This gives a bunch of answers.
¤ http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&q=dataset+csv+paul&qt_s=Search
¤
¤ Maybe you can check this answers as long as Paul has not answered you
¤ himself.
¤ Be aware that where he tells that it does not work in the first answer
¤ Dataset to CSV that is talked about updating a csv file.
¤
¤ I hope this gives some help,
¤
¤ Cor
¤

Cor,

I haven't developed any code examples that export data from a DataSet (DataTable) to any type of
file (in case anyone was looking).

I still favor direct exports from another data source, when that is possible, instead of using a
DataSet as the intermediate data store.


Paul
~~~~
Microsoft MVP (Visual Basic)
 
C

Cor Ligthert [MVP]

Paul,

Thanks for this answer because I thought that I had seen it. Now I know it
was not and probably I mixed up an answer from a direct datasource (which I
have seen when I was searching) with that from the dataset.

Cor
 

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

Similar Threads


Top