我应该用比较的DBNull?使用或者的DBNull.Value的ToString()。IsNullOrEmpty() [英] What should I use to compare DBNull ? Using DBNull.Value or ToString().IsNullOrEmpty()

查看:260
本文介绍了我应该用比较的DBNull?使用或者的DBNull.Value的ToString()。IsNullOrEmpty()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以检查一个的DBNull 使用任何方法数据行。

I can check for a DBnull on a data row using any of the methods.

通过使用

if(dr[0][0]==DBNull.Value)
//do somethin

或做

if(dr[0][0].ToString().IsNullOrEmpty())
//do something

在这两种情况下我会得到同样的结果。

In Both Cases I will be getting same result.

但哪一个是conecptually正确的做法。这是将使用更少的资源

But Which one is conecptually right approach. Which was will use less resources

推荐答案

第一种方式是有些正确的。 但是,比较公认的做法是:

The first way is somewhat correct. However, more accepted way is:

if ( dr[0][0] is DBNull )

和第二种方式是绝对不正确。如果使用第二种方法,你会得到真正的有两种情况:

And the second way is definitely incorrect. If you use the second way, you will get true in two cases:

  1. 您的价值为DBNull
  2. 您的值是一个空字符串

这篇关于我应该用比较的DBNull?使用或者的DBNull.Value的ToString()。IsNullOrEmpty()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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