指定的演员阵容无效
我尝试使用以下代码从数据库中获取 Score_Waarde
值:
critid = critid_arr[teller2].ToString();
int scorehulp = 0;
string userid = Session["userid"].ToString();
SqlCommand cmd3 = new SqlCommand("SELECT Score_Waarde FROM Score WHERE Crit_ID = '" + critid + "' AND User_ID = '" + userid + "' ", con);
scorehulp = (int)cmd3.ExecuteScalar();
当我尝试运行此代码时,出现以下错误:指定的转换无效。 我不明白为什么会收到此错误,因为 critid
和 userid
给出了正确的值。
I'm trying to get the Score_Waarde
value from my database using the following code :
critid = critid_arr[teller2].ToString();
int scorehulp = 0;
string userid = Session["userid"].ToString();
SqlCommand cmd3 = new SqlCommand("SELECT Score_Waarde FROM Score WHERE Crit_ID = '" + critid + "' AND User_ID = '" + userid + "' ", con);
scorehulp = (int)cmd3.ExecuteScalar();
When I try to run this I get the following error: Specified cast is not valid.
I don't understand why I'm getting this error because critid
and userid
are giving the correct values.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最初收到此错误(我的 C# 代码
,其中
TotalItemCount
为int
类型,即使 SP 很好并且给出了正确的结果。我只是摆脱了这个错误通过添加以下代码来修复 SPI was originally getting this error (my C# code
where
TotalItemCount
was ofint
type, even though the SP was fine & was giving proper result. I got rid of this just by fixing the SP by adding the following code您的 SQL 可能会返回不同的数字类型,例如
long
或decimal
,或者显然是string
。调用
Convert.ToInt32
,它没有 拆箱转换的限制。Your SQL is probably giving back a different numeric type, such as
long
ordecimal
, or, apparently,string
.Call
Convert.ToInt32
, which doesn't have the limitations of an unboxing cast.