Convert a single DataTable column to CSV

Using VB.NET, what is the most concise way to convert a single DataTable column to CSV? Values ​​are integers, so I don't have to worry about escaping or encoding characters.

+4
source share
1 answer

What does it mean to convert to CSV? If you want to generate a comma-separated string, you can use this ( tbl is your DataTable and Int-Column is the name of DataColumn):

 String.Join(",", (From row In tbl.AsEnumerable Select row("Int-Column")).ToArray) 

CSV is usually a file format where columns are separated by a comma (or other delimiters) and lines are separated by new lines. Therefore, you just need to replace String.Join("," with String.Join(Environment.NewLine

+10
source

All Articles