Reputation: 2259
Using VB.NET, what is the most concise way to convert a single column of a DataTable to a CSV? The values are integers, so I don't need to worry about character escaping or encoding.
Upvotes: 5
Views: 4528
Reputation: 460108
What do you mean with "convert to CSV"? If you want to generate a string with comma-separated values, you can use this(tbl
is your DataTable and Int-Column
is the name of the DataColumn):
String.Join(",", (From row In tbl.AsEnumerable Select row("Int-Column")).ToArray)
A CSV normally is a file-format where the columns are separated by comma(or other separators) and the rows are separated by new lines. Hence you simply have to replace String.Join(","
with String.Join(Environment.NewLine
Upvotes: 11