【发布时间】:2012-07-04 12:02:07
【问题描述】:
我只想将 List 添加为 DataTable 整行。这是我尝试过的代码。
private static DataTable _table = new DataTable();
List<string> tempList = new List<string>();
// tempList = {"A1","A2","A3","A4","A5","A6"}
_table.Rows.Add(tempList);
预期输出:
col1|col2 |col3 |col4 |col5| col6
----+-----+-----+------+----+--
row1 A1 | A2 | A3 | A4 | A5 | A6
但是这对我不起作用。它将数据集合插入到第一列。
实际输出:
col1 |col2 |col3 |col4 |col5| col6
----------+-----+-----+------+----+--
row1 A1,A2,A3.| | | | |
请帮助我使用列表添加整行。谢谢
【问题讨论】:
-
你在DataTable上定义了一些列吗?
-
是的。但是 tempList.ToArray() 是解决方案。 :0
-
理想情况下你需要同时做这两个,否则你会遇到问题:-)