为了将 ExpandoObjects 塞入类似以下两个网格的网格中,我们进行了两次尝试。
这不起作用:
var data = _d.Query<dynamic>(_script); // returns IEnumerable<ExpandoObject>
IDictionary<string, object> c = (IDictionary<string, object>)data.FirstOrDefault();
DataTable dt = new DataTable();
dt.BeginLoadData();
dt.Columns.AddRange(c.Keys.Select(k => new DataColumn(k)).ToArray());
data.Select(r => dt.Rows.Add((r as IDictionary<string, object>).Values.ToArray()));
dt.EndLoadData();
但这确实:
dt.Columns.AddRange(c.Keys.Select(k => new DataColumn(k)).ToArray());
foreach (IDictionary<string, object> r in data)
dt.Rows.Add(r.Values.ToArray());
为什么?