Public Property Duration() As Integer
Get
Try
Return CType(Item(DurationColumn), Integer)
Catch e As Global.System.InvalidCastException
Throw New Global.System.Data.StrongTypingException("The value for column 'Duration' in table 'T_MembershipSale' is DBNull.", e)
End Try
End Get
Set(ByVal value As Integer)
Item(DurationColumn) = value
End Set
End Property
What happens when a user wants to allocate "" as Item(DurationColumn) to integer? I get an exception. Any clean solution to avoid this and set 0 for ""?
Use Int32.TryParse:
Dim number as Integer
If Not Int32.TryParse(DurationColumn, number) Then number = 0
return number
This handles the case of "", as well as any other invalid value (i.e. non-number) the user might enter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With