【发布时间】:2018-08-04 09:29:44
【问题描述】:
我有一本字典像
Dictionary<string, List<string>> first=new Dictionary<string, List<string>>();
我想将此字典绑定到数据表,以便数据表 ColumnName 应该是字典的键,并且相应的列应该包含它们的字典值。 我尝试了什么:
Dictionary<string, List<string>> some= new Dictionary<string, List<string>>();
System.Data.DataTable dt = new System.Data.DataTable();
foreach (var entry in some)
{
if (entry.Value.Count > 0)
{
dt.Columns.Add(entry.Key);
//entry.Value.count is not same for all entry.Key
foreach (var value in entry.Value)
{
DataRow row = dt.NewRow();
row[entry.Key] = value;
dt.Rows.Add(row);
}
}
}
我当然知道,上面的代码有一些错误来实现以下结果 DesirrdResultImage 有什么建议吗?
【问题讨论】:
-
有什么建议吗?
-
这应该是
row[entry.Key] = value; -
@FaizanRabbani 是的,我现在要编辑。
-
确切的错误是什么?
-
对于每一列,数据都添加到前一列最后一行的旁边。 @Haytam
标签: c# winforms dictionary datatable