c#.net需要解决"System.InvalidCastException"当我们使用LINQ [英] c#.net need to resolve "System.InvalidCastException" when we using LINQ
本文介绍了c#.net需要解决"System.InvalidCastException"当我们使用LINQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友,
我在这里发布了我的代码供您参考.
hi friends,
here with i have post my code for your reference.
DataTable dtConfig = TesterSlotTypeGroupDAL.GetConfiguredTSTGroupRows();
DataTable dt = new DataTable("dTable");
DataRow dr; int iColCtr = 2;
var vGroups = from c in dtConfig.AsEnumerable()
select new
{
TST_GroupId = c.Field<decimal>("id"),
TST_Group = c.Field<string>("TST Group")
};
foreach (var vGroup in vGroups.Distinct())
{
if (dt.Rows.Count == 0)
{
dt.Columns.Add("id");
dt.Columns.Add("TST Group");
dt.Columns.Add("Machine Size Slot");
dt.Columns.Add("Slot");
}
dr = dt.NewRow();
dr[0] = vGroup.TST_GroupId.ToString();
dr[1] = vGroup.TST_Group.ToString();
dt.Rows.Add(dr);
}
dgv.DataSource = dt;
注意:
在此行中的foreach (var vGroup in vGroups.Distinct())
我遇到了错误.您能否给我一个解决此问题的方法..,
问候
Siva
note:
foreach (var vGroup in vGroups.Distinct())
in this line i am getting error. can you pls give me a idea how to resolve this issue..,
Regards
Siva
推荐答案
尝试vGroups.AsEnumerable().Distinct()
这篇关于c#.net需要解决"System.InvalidCastException"当我们使用LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文