PC Review


Reply
Thread Tools Rate Thread

Dataset to CSV file

 
 
=?Utf-8?B?QnJpYW5ESA==?=
Guest
Posts: n/a
 
      4th Aug 2005
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
 
Reply With Quote
 
 
 
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      5th Aug 2005
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=e...ul&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


 
Reply With Quote
 
Paul Clement
Guest
Posts: n/a
 
      5th Aug 2005
On Fri, 5 Aug 2005 08:40:26 +0200, "Cor Ligthert [MVP]" <(E-Mail Removed)> wrote:

¤ 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=e...ul&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)
 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      5th Aug 2005
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


 
Reply With Quote
 
shriop
Guest
Posts: n/a
 
      5th Aug 2005
My csv parser will do it, roughly with the same type of logic as what
you're using but providing you with all the proper escaping. Look for
the WriteAll method of CsvWriter. http://www.csvreader.com

BrianDH wrote:
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataSet XSD file Dragon Microsoft C# .NET 1 24th Feb 2006 03:48 AM
DataSet to MDB file =?Utf-8?B?UEpTaW1vbg==?= Microsoft VB .NET 5 21st Apr 2005 05:45 PM
CSV file into dataset EMW Microsoft Dot NET 3 22nd Feb 2004 05:51 PM
How can I create an xsd file out of a Dataset class file? Babu Mannaravalappil Microsoft ADO .NET 1 4th Aug 2003 12:44 AM
Converting Dataset to a .IND file( dbaseIV index file) Hari Microsoft ADO .NET 0 12th Jul 2003 11:02 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:57 AM.