我有一个SqlString
类型的属性,当前返回Null。
_oData.Customer.Name
以下是我尝试过的以下无效的检查。
IsNothing(_oData.Customer.Name)
_oData.Customer.Name.IsNull
_oData.Customer.Name.Value IsNot Nothing
_oData.Customer.Name = Nothing
每个都会导致以下错误。如何真正检查Null的值。
数据是空的。无法在Null值上调用此方法或属性。
_oData.Customer
具有其他属性的值。
修改
添加具有name属性的类。以下是Customer
类
Private mName As SqlTypes.SqlString
Public Property Name() As SqlTypes.SqlString
Get
Return mName
End Get
Set(ByVal value As SqlTypes.SqlString)
mName = value
End Set
End Property
修改-2
好像是处理ternery操作的问题
这有效
If _oData.Customer.Name.IsNull Then
CName = ""
Else
CName = _oData.Customer.Name
End If
这不是
CName = IIf(_oData.Customer.Name.IsNull, "", _oData.Customer.Name.Value)
任何人都可以告诉我为什么在使用三元操作时这不起作用?
答案 0 :(得分:0)
你应该使用Microsoft.VisualBasic.Information.IsDBNull()方法:
If IsDBNull(_oData.Customer.Name) Then