[英]Specified cast is not valid exception
这是我的代码
var result = (from row1 in table.AsEnumerable()
join row2 in tabelPopup.AsEnumerable()
on row1.Field<string>("CallID") equals
row2.Field<string>("callID")
where row1.Field<string>("Direction") == "I"
select new
{
Agent = row1.Field<string>("Agent"),
StartTime = row1.Field<DateTime>("StartTime"),
Reason = row2.Field<string>("Reason")
});
其中table
和tablePopup
是数据table
变量。
我有这个例外:
Specified cast is not valid
在此代码上:
new
{
Agent = row1.Field<string>("Agent"),
StartTime = row1.Field<DateTime>("StartTime"),
Reason = row2.Field<string>("Reason")
}
确保您的列定义与row1.field <>中使用的类型匹配。 即代理是字符串,开始时间是日期时间,原因是字符串。 这很可能是由于StartTime不是日期时间类型。
可能StartTime
不是来自DateTime
类型。 因此,您会收到此异常。 尝试将其转换。 如果正确,则应将其转换为DateTime
或仅检索字符串值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.