[英]How to check for Null on a `SqlString` in VB.Net 2.0?
我有一個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
在其他屬性上具有值。
編輯
添加具有名稱屬性的類。 這是在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
確定似乎與實習生操作的方式有關
這有效
If _oData.Customer.Name.IsNull Then
CName = ""
Else
CName = _oData.Customer.Name
End If
這不是
CName = IIf(_oData.Customer.Name.IsNull, "", _oData.Customer.Name.Value)
誰能告訴我為什么使用三元運算時不起作用?
您應該使用Microsoft.VisualBasic.Information.IsDBNull()方法:
If IsDBNull(_oData.Customer.Name) Then
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.