我得到这种类型的错误,任何人都可以帮助我吗? [英] I'm getting this type of Error,can anybody help me ?

查看:75
本文介绍了我得到这种类型的错误,任何人都可以帮助我吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从DBNull类型到Integer类型的转换无效。

解决方案

您需要使用IsDBNull检查DBNull值。查看此链接:

http:// msdn.microsoft.com/en-us/library/tckcces5%28v=vs.90%29.aspx [ ^ ]



祝你好运!


1.您正在尝试从DB中读取一个允许NULL值的int值,并且您当前字段在数据库中具有与 DBNull <等效的NULL值/ code>在C#代码中。



2.解决方案是,在您的读者中管理此案例,如下一个示例所示:

  int  stockQuantity =(读者[  Stock] == DBNull.Value? 0  :(  int )reader [  Stock]); 


Conversion from type 'DBNull' to type 'Integer' is not valid.

解决方案

You need to check for DBNull values using IsDBNull. Check this link:
http://msdn.microsoft.com/en-us/library/tckcces5%28v=vs.90%29.aspx[^]

Good luck!


1.You are trying to read an int value from the DB that allow also NULL values, and your current field has NULL value in the database that is equivalent with DBNull in the C# code.

2.The solution is, that in your reader to manage this case like in the next example:

int stockQuantity = (reader["Stock"] == DBNull.Value ? 0 : (int)reader["Stock"]);


这篇关于我得到这种类型的错误,任何人都可以帮助我吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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