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
大家看看这两个函数功能上有什么不同的地方
1.
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 IntegerReturn IIF(IsDBNull(obj),0,Convert.ToInt32(obj))
End Function
相同,不同,相同,不同........
我认为不同,根据我的测试结果,我猜测代码2更接近代码3
3.
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 ,“合格”,“不合格”)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。