【发布时间】:2015-07-08 17:56:56
【问题描述】:
我在 sql 中使用的 'userid' 是 int 数据类型,而在后端(.cs)中也使用了相同的 int 数据类型,那么为什么会抛出这个错误:'specified cast is not valid'
var userRowsCustId = dsCustReg.Tables[0]
.AsEnumerable()
.Select(r => r.Field<int>("AccountNo"));
var allRowsCustId = dsAllTables.Tables[0]
.AsEnumerable()
.Select(r => r.Field<int>("UserId"));
IEnumerable<int> allIntersectingCustIds = userRowsCustId.Except(allRowsCustId);
if (allIntersectingCustIds.Any())
{
}
这个错误的解决方法是什么?
r => r.Field<int>("AccountNo") 抛出错误
【问题讨论】:
-
您是否使用
SqlDataAdapter填写表格或如何填写DataTable?AccountNo也是int列吗?查看调试器中的dsCustReg.Columns。 -
数据库中
AccountNo和UserId是什么数据类型? -
另外,您的代码似乎存在命名或逻辑问题。相交通常意味着它们共享相同的值,但
Except返回所有不存在于客户行中的用户行。也许你想使用Intersect。 -
也许你的字段是
int?(nullable int) -
userid 和 account no 在前端我显示 accno 和在后端使用用户 id 相同