【发布时间】:2011-08-03 16:04:25
【问题描述】:
我在尝试获取 此 Linq 查询中的总和时遇到以下错误:
InvalidCastException 未处理。指定的演员表无效。
我使用 DataType 属性三重检查该列是否实际上是 Double,它确实是。
foreach (DataColumn item in _dttMasterViewTransaction.Columns)
{
if (item.ColumnName == "Dr")
{
//Outputs: System.Double!
MessageBox.Show(item.DataType.ToString());
}
}
var datos = _dttMasterViewTransaction.AsEnumerable().Where(r => (int)r["Entity"] == FundsID).Select(r => new EntityJESummary()
{
JEId = (int)r["JE ID"],
JEGroupingId = (int)r["JE Group"],
PartnershipId = (int)r["Entity"],
BookingDate = Convert.ToDateTime(r["GL Date"]),
EffectiveDate = Convert.ToDateTime(r["Effective Date"]),
Allocated = Convert.ToBoolean(r["Allocated"]),
JEEstate = (int)r["JE State"],
JEComments = r["JE Comments"].ToString(),
Debit = _dttMasterViewTransaction.AsEnumerable().Where(s => (int)r["Entity"] == FundsID).Sum(s => (double)s["Dr"]),
Credit = _dttMasterViewTransaction.AsEnumerable().Where(s => (int)r["Entity"] == FundsID).Sum(s => (double)s["CR"])
}).First();
关于为什么会发生这种情况的任何建议?
【问题讨论】:
-
您是否试图将字符串转换为
ints?
标签: c# linq casting double datarow