开发者

Convert single column of a DataTable to CSV

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜