zoukankan      html  css  js  c++  java
  • Data is Null. This method or property cannot be called on Null values.

    reader = cmd.ExecuteReader()
           Do While reader.Read()
               Application("aaa" + reader.GetInt32(0).ToString()) = IIf(IsDBNull(reader.Item(1)), False, reader.GetBoolean(1))
               Application("bbb" + reader.GetInt32(0).ToString()) = IIf(IsDBNull(reader.Item(2)), False, reader.GetBoolean(2))
           Loop

    --------------------------------

    Data is Null. This method or property cannot be called on Null values.

    --------------------------------

    The problem, I think is that the IIf method evaluates the false portion [i.e. reader.GetBoolean(2) ] even if the expression [i.e. IsDBNull(reader.Item(1))]evaluates to True.

    -------------------------------

    It has to do with the IIf statement. It evaluates both conditions, regardless of whether the first one is true or not. In other words, it does not short-circuit. You need to use the regular VB If-Else-End If construct to make this logic work the way you want.

    --------------------------------

    http://forums.asp.net/p/1487348/3486861.aspx#3486861

    http://forums.asp.net/p/958920/1939165.aspx#1939165

    http://www.codeproject.com/Messages/772581/listview-iif-statement.aspx

    VB.NET中IF与IIF的区别

    大家看看这两个函数功能上有什么不同的地方
    1.

    Private Function GeteachQty()Function GeteachQty(ByVal obj As Object) As Integer
    If IsDBNull(obj) = False Then
    Return Convert.ToInt32(obj)
    Else
    Return 0
    End If
    End Function

    2.

    Private Function GeteachQty()Function GeteachQty(ByVal obj As Object) As Integer

    Return IIF(IsDBNull(obj),0,Convert.ToInt32(obj))
    End Function

    相同,不同,相同,不同........
    我认为不同,根据我的测试结果,我猜测代码2更接近代码3
    3.

    Private Function GeteachQty()Function GeteachQty(ByVal obj As Object) As Integer
    Dim resule as Integer=Convert.ToInt32(obj)
    If IsDBNull(obj) = False Then
    Return resule 
    Else
    Return 0
    End If
    End Function

    如果我的猜测没错的活,那么IF与IIF就有着本质上的区别,根本不能互换,各位在使用过程中一定要小心。

    http://www.cnblogs.com/weisai/archive/2008/04/18/244454.html

    VB IIf语句使用方法

    函数主要功能根据表达式的值,来返回两部分中的其中一个。
    语法
    IIf(expr, truepart, falsepart)
    格式
    变量=IIf(条件,true部分,False部分)
    IIf 函数的语法含有下面这些命名参数:
    部分 描述
    expr 必要参数。用来判断真伪的表达式。
    truepart 必要参数。如果 expr 为 True,则返回这部分的值或表达式。
    falsepart 必要参数。如果 expr 为 False,则返回这部分的值或表达式。
    说明
    由于 IIf 会计算 truepart 和 falsepart,虽然它只返回其中的一个。因此要注意到这个副作用。
    例如,如果 falsepart 产生一个被零除错误,那么程序就会发生错误,即使 expr 为 True。
    实例:
    G=61
    Print IIf(G>=60 ,“合格”,“不合格”)

  • 相关阅读:
    对于有API接口数据的监测
    网站、域名、IP、URL、URI、IRI
    面向对象总结
    封装示例:游戏开发
    面向对象基础2
    继承与多态
    如何引用第三方同级以及不同级目录下的的py文件
    Weblogic常见报错以及解决方法
    深度解读企业云上办公利器「无影云电脑」
    java根据模板导出pdf
  • 原文地址:https://www.cnblogs.com/emanlee/p/1658865.html
Copyright © 2011-2022 走看看