Export DataSet to CSV file

9 views
Skip to first unread message

heartland

unread,
Mar 13, 2008, 4:18:00 PM3/13/08
to CSVChat
Hi,

I use CSVWriter.WriteAll method to export DataTable to CSV file. It
works beautifully. However, I need to reformat one of the fields in
the table in the writing (no need to reformat the field in the
table). I know that I can read the table and parse the contents into
columes, reformat the colume and write all columes into CSV file. Is
there an eay way? I need to do the samething for many tables.

Thank you very much in advance.

Hugh

shriop

unread,
Mar 13, 2008, 7:54:46 PM3/13/08
to CSVChat
No, unfortunately there's no current built in way to make this easier.
The code that writes out the content of the DataTable is kind of long
and drawn out, so to do what you want to do today, you'd have to write
out all that code and change the line that's calling the default
ToString overload to instead call a formatted ToString for certain
columns. It would probably be easier to reformat the value in the
DataTable, unless the data in the DataTable is typed to a non-string I
suppose. I need to extend the functionality of the WriteAll method to
do some of these extra things, but somehow without cluttering up the
interface too much. Design decisions suck. Do you have an idea of how
you would want to specify the optional formats? And how you would have
had that content accessible for your last question?

Bruce Dunwiddie

heartland

unread,
Mar 14, 2008, 9:48:44 AM3/14/08
to CSVChat
Hi Bruce,

Thanks for your reply. I do not have to use WriteAll method or write
whole table. I think it would be very helpful to have "Column Format"
feature in WriteAll method. For example, we often need to reformat
"DateTime" in the database table to "Date" in real life. We do not
care about the time. But in the database it is "DateTime" and there
is no "Date" format.

Hugh
Reply all
Reply to author
Forward
0 new messages