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
大家看看这两个函数功能上有什么不同的地方
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 ,“合格”,“不合格”)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
2008-01-28 SQL Server 字符串函数速查