gpt4 book ai didi

.net - 我应该用什么来比较 DBNull ?使用 DBNull.Value 或 ToString().IsNullOrEmpty()

转载 作者:行者123 更新时间:2023-12-03 11:56:00 34 4
gpt4 key购买 nike

我可以检查 DBnull使用任何方法在数据行上。

要么通过使用

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

或者通过做
if(dr[0][0].ToString().IsNullOrEmpty())
//do something

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

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

最佳答案

第一种方式有点正确。
然而,更被接受的方式是:

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

而第二种方式肯定是不正确的。如果你使用第二种方式,你会在两种情况下得到true:
  • 您的值为 DBNull
  • 您的值为空字符串
  • 关于.net - 我应该用什么来比较 DBNull ?使用 DBNull.Value 或 ToString().IsNullOrEmpty(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3393958/

    34 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com