开发者

Convert single column of a DataTable to CSV

开发者 https://www.devze.com 2023-03-29 16:13 出处:网络
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.Wha

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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消