DataView 中按列分组的总和数据的 LINQ 结果错误?
我收到以下错误:
指定的演员阵容无效
以下行在出现错误 row.Field
后突出显示此内容。
这是我的代码:
var query = from row in _Hdt.AsEnumerable()
group row by row.Field<DateTime>("DATE") into grp
orderby grp.Key
select new
{
Date = grp.Key,
Sum = grp.Sum(r => r.Field<decimal>("KW"))
};
foreach (var grp in query)
{
Console.WriteLine("{0}\t{1}", grp.Date, grp.Sum);
}
I am getting the following error:
Specified cast is not valid
The following row is highlighting this after error row.Field<DateTime>("DATE")
.
This is my code:
var query = from row in _Hdt.AsEnumerable()
group row by row.Field<DateTime>("DATE") into grp
orderby grp.Key
select new
{
Date = grp.Key,
Sum = grp.Sum(r => r.Field<decimal>("KW"))
};
foreach (var grp in query)
{
Console.WriteLine("{0}\t{1}", grp.Date, grp.Sum);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查数据库列类型是否确实与 DateTime 兼容,以及表中该列是否包含 Null 值。
Null 无法转换为 DateTime。
Check if the database column type is really compatible to DateTime, and if the table contains Null values in that column.
Null cannot be converted to DateTime.
尝试
或
Try
or