指定的转换是无效 [英] Specified cast is not valid

查看:109
本文介绍了指定的转换是无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我几乎与我的项目做,但是最后一个讨厌的bug(我不知道如何解决)是保持我了。

I'm almost done with my project, but one last irritating bug (which I don't know how to fix) is keeping me up.

我想用下面的code至从我的数据库中的 Score_Waarde 值:

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();

当我尝试运行此我得到以下错误:指定的转换是无效
我不明白为什么我得到这个错误,因为 critid 用户ID 是给正确的值。没有人有一个想法?

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. Does anyone have an idea?

grtz,

推荐答案

您的SQL可能是回馈不同的数字类型,如小数,或,很显然,字符串

Your SQL is probably giving back a different numeric type, such as long or decimal, or, apparently, string.

呼叫 Convert.ToInt32 ,它不具备<一个href=\"http://blogs.msdn.com/b/ericlippert/archive/2009/03/19/re$p$psentation-and-identity.aspx\">limitations一个拆箱投。

这篇关于指定的转换是无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆