象以下两项尝试一样,将奥标扩大到一些电网。
这一工作:
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());
为什么?