DEV Community

Discussion on: How to use C# to convert a data table to CSV

Collapse
 
jayjeckel profile image
Jay Jeckel

This article doesn't explain how to convert a DataTable to CSV, it explains how to download a library to convert a DataTable to Excel worksheet and convert that worksheet to CSV.

In other words, this article doesn't at all provide what is promised by the title.

The sad part is, this isn't that complicated of a thing to do and definitely doesn't require a separate library and allocation of an intermediate excel worksheet. Proper solutions can be found with a simple googling (eg stackoverflow), but the gist is easy to lay out.

  1. Join the table's column names with a comma delimiter and write line to file.
  2. Join each row's items with a comma delimiter and write line to file.

Boom. Simple as that. No unneeded excel object or external dependency.

Collapse
 
ironsoftware profile image
IronSoftware

You should write an article on it then :)