By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,550 Members | 918 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,550 IT Pros & Developers. It's quick & easy.

GetType of custom Property set to nothing

P: n/a
I want to return the proper Null to the SQL Database if my property is
nothing
Also I thought about creating a function so I don't have to put so many if
statement for each property for each classes etc.
However if I call ReturnValue(myClass.CompanyName) and CompanyName is
Nothing then it crash where it shoud return SqlTypes.SqlString.Null
Private _CompanyName As String
<ComponentModel.Browsable(True), ComponentModel.Description("CompanyName"),
ComponentModel.ReadOnly(False)> _
Public Property CompanyName() As String Implements iCompany.CompanyName
Get
Return _CompanyName
End Get

Set(ByVal Value As String)
Me._CompanyName = Value
End Set
End Property

Function ReturnValue(ByVal thisObject As Object) As Object
Try
If IsNothing(thisObject) Then

""""" CRASH HERE """ Because thisObject is nothing so I cannot get the type
Select Case thisObject.GetType.ToString
Case GetType(System.String).ToString
Return SqlTypes.SqlString.Null
Case GetType(System.Boolean).ToString
Return SqlTypes.SqlBoolean.Null
Case Else
Return SqlTypes.SqlString.Null
End Select
Else
Return thisObject
End If

Catch ex As Exception
Return SqlTypes.SqlString.Null
End Try
End Function

Thanks for the help

Nicolas
Mar 28 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Function ReturnValue(ByVal thisObject As Object) As Object
Try
If IsNothing(thisObject) Then

""""" CRASH HERE """ Because thisObject is nothing so I cannot get the
type
Select Case thisObject.GetType.ToString
Case GetType(System.String).ToString
Return SqlTypes.SqlString.Null
Case GetType(System.Boolean).ToString
Return SqlTypes.SqlBoolean.Null
Case Else
Return SqlTypes.SqlString.Null
End Select
Else
Return thisObject
End If

Catch ex As Exception
Return SqlTypes.SqlString.Null
End Try
End Function

Nick,

If you want to return null if the object is nothing, try:

Function ReturnValue(ByVal Value As Object) As Object
If Value Is Nothing
Return DBNull.Value
Else
Return Value
End If
End Function
HTH,
Mythran

Mar 28 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.