Data is Null. This method or property cannot be called on Null values.
2010-01-28 23:29
981 查看
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
Private Function GeteachQty()Function GeteachQty(ByVal obj As Object) As Integer
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 ,“合格”,“不合格”)
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
Private Function GeteachQty()Function GeteachQty(ByVal obj As Object) As Integer
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 ,“合格”,“不合格”)
相关文章推荐
- MOSS爬网问题Error from SharePoint site: Data is Null. This method or property cannot be called on Null values
- Data is Null. This method or property cannot be called on Null values.错误分析
- Property or field 'LevelName' cannot be found on null
- Property or field 'str' cannot be found on object of type 'com.yubai.EL.DemoService' - maybe not pub
- Page is already covered by another Data Binder. Cannot be covered by this Data Binder again
- Vue报错笔记(1)vue.js:515 [Vue warn]: Property or method "name" is not defined on the instance but refere
- Is there something like [Data Source Update Mode =? OnPropertyChanged] in DataGrid or DataGridView?
- After upgrading the ebPart Assembly "Web Part Error: A Web Part or Web Form Control on this Page cannot be displayed .."
- The method or function that was called cannot be used in the manner requested.
- 错误:Property or field 'default' cannot be found on object of type 'com.netflix.appinfo.InstanceInfo'
- future method cannot be called from a future or batch method
- File xxx.ps1 cannot be loaded because the execution of scripts is disabled on this system
- MSSQL: Invoke or BeginInvoke cannot be called on a control until the window handle has been created.
- spring同时使用aop和spel表达式出错:Property or field 'instrument' cannot be found on object of type 'com.sun.pr
- The action cannot be completed. The connection to Microsoft Exchange is unavailable. Outlook must be online or connected to complete this action.
- SQL Server 2008 : Invoke or BeginInvoke cannot be called on a control until the window handle has ..
- 打开Eclipse提示“The default workspace “xxxx” is in use or cannot be created Please choose a different on
- spring同时使用aop和spel表达式出错:Property or field 'instrument' cannot be found on object of type 'com.sun.pr
- Property or field 'siteUrl' cannot be found on object of type 'xx' - maybe not public?
- PowerShell: 如何解决File **.ps1 cannot be loaded because the execution of scripts is disabled on this system.