Search code examples
c#csvdatarow

Datarow to CSV line C#


Is there any form of statement which converts a datarow to a CSV line so it could be written to a .csv file? (with or without steps in between)


Solution

  • A quick Google search turned this up: http://www.rcs-solutions.com/blog/2009/01/15/ConvertDataTableToCSVViaExtensionMethod.aspx

    It's a bit dated. There is no native way to do it, so you'll need to either iterate over the datatable using looping constructs, but I'd recommend using LINQ methods as it will be much cleaner.