这很令人困惑,我使用AsDataView将查询结果绑定到dgv,以下方式可以正常工作:
var query = from c in myDatabaseDataSet.Diamond where c.p_Id == p_Id select c;
dataGridView1.DataSource = query.AsDataView();
然而,这个会导致一个错误:
var query = from item in myDatabaseDataSet.Items
where item.p_Id == p_Id
join diamond in myDatabaseDataSet.Diamond
on item.p_Id equals diamond.p_Id
join category in myDatabaseDataSet.DiamondCategory
on diamond.dc_Id equals category.dc_Id
select new
{
Product = item.p_Name,
Weight = diamond.d_Weight,
Category = category.dc_Name
};
dataGridView1.DataSource = query.AsDataView();
错误:
Instance argument: cannot convert from
'System.Collections.Generic.IEnumerable<AnonymousType#1>' to
'System.Data.DataTable'
为什么AsDataView在查询(List)中没有显示出来?如何将上述查询绑定到dgv?