How can DBNull not equal DBNull

橙三吉。 提交于 2019-12-05 05:44:30

Try using

Convert.IsDBNull method.

I think you problem is that in fact

DBNull.Value == null 
//is always false

The DBNull is a special class for comparisons on values returned from the dB so you actualy need to check for a null condition AND a DBNull.value if your array contains both.

EDIT: Sorry looking closer at your code you may just need to reverse your OR operation. If o == null your first statement will blow up with your exception. Try:

if (o != null || o == DBNull.Value) 

may be such comparison helps

if ( !o.GetType().Equals( DBNull.Value ) )

or

if (o is DBNull)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!