R
Ryan0827
Guest
I'm trying to bind TextBox.Text to a strongly typed datarow field that has a Decimal datatype. For some reason, the dataset designer doesn't allow me to set the NullValue property from "(Throw exception)" to "(Nothing)" for a DataColumn with Decimal datatype. However, I can for String datatypes. That makes no sense to me. How can I bind my TextBox text to a nullable decimal field?
Because of this, the designer code for my decimal column throws a System.Data.StrongTypingException: 'The value for column 'Latitude' in table 'Contact' is DBNull.' Inner Exception InvalidCastException: Conversion from type 'DBNull' to type 'Decimal' is not valid.
when the binding object attempts to access the column value. See designer code below:
Here a better description of my issue:
Microsoft: Please allow Null values to be returned from strongly typed datasets! - Mike Wilson
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "15.0.0.0")> _
Public Property Country() As String
Get
If Me.IsCountryNull Then
Return Nothing
Else
Return CType(Me(Me.tableContact.CountryColumn),String)
End If
End Get
Set
Me(Me.tableContact.CountryColumn) = value
End Set
End Property
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "15.0.0.0")> _
Public Property Latitude() As Decimal
Get
Try
Return CType(Me(Me.tableContact.LatitudeColumn),Decimal)
Catch e As Global.System.InvalidCastException
Throw New Global.System.Data.StrongTypingException("The value for column 'Latitude' in table 'Contact' is DBNull.", e)
End Try
End Get
Set
Me(Me.tableContact.LatitudeColumn) = value
End Set
End Property
Ryan
Continue reading...
Because of this, the designer code for my decimal column throws a System.Data.StrongTypingException: 'The value for column 'Latitude' in table 'Contact' is DBNull.' Inner Exception InvalidCastException: Conversion from type 'DBNull' to type 'Decimal' is not valid.
when the binding object attempts to access the column value. See designer code below:
Here a better description of my issue:
Microsoft: Please allow Null values to be returned from strongly typed datasets! - Mike Wilson
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "15.0.0.0")> _
Public Property Country() As String
Get
If Me.IsCountryNull Then
Return Nothing
Else
Return CType(Me(Me.tableContact.CountryColumn),String)
End If
End Get
Set
Me(Me.tableContact.CountryColumn) = value
End Set
End Property
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "15.0.0.0")> _
Public Property Latitude() As Decimal
Get
Try
Return CType(Me(Me.tableContact.LatitudeColumn),Decimal)
Catch e As Global.System.InvalidCastException
Throw New Global.System.Data.StrongTypingException("The value for column 'Latitude' in table 'Contact' is DBNull.", e)
End Try
End Get
Set
Me(Me.tableContact.LatitudeColumn) = value
End Set
End Property
Ryan
Continue reading...