【发布时间】:2014-07-04 03:24:08
【问题描述】:
尝试通过查询将 Linq 组返回到 DataTable。得到错误
不能隐式转换类型 'System.Collections.Generic.IEnumerable
' 到 'System.Collections.Generic.IEnumerable '。一个 存在显式转换(您是否缺少演员表?)
我正在查询一个名为 Vendors 的 DataTable,其中的数据如下:
Vendor Name
654797 Lowes
897913 Home Depot
800654 Waffle House
供应商在数据库中存储为 char(6),名称也为 char...不要问我为什么,我只是在这里工作 :)
DataTable VendorsDT = New DataTable();
DataColumn VenName = VendorsDT.Columns.Add("Name", typeof (string));
DataColumn VenCode = VendorsDT.Columns.Add("Vendor", typeof(string));
IEnumerable<DataRow> Vendors = from row in alertsDT.AsEnumerable()
group row by new { Name = row.Field<string>("Name"), Vendor = row.Field<string>("Vendor") } into z
select new
{
Name = z.Key.Name,
Vendor = z.Key.Vendor,
};
VendorsDT = Vendors.CopyToDataTable();
【问题讨论】: