Wednesday, 14 August 2013

Nullable fails - dbnull to integer

Nullable fails - dbnull to integer

In my class:
Namespace Chauffeurs Public Class Algemeen Property FirmaId As Integer?
Property Firma As String
Public Sub New()
End Sub
Public Sub New(ByVal firmaId As Integer?, Optional ByVal id As
Integer = 0)
'I don't even reach this point.
Me.FirmaId = firmaId
End Sub
End Class
Public Class Yard
Inherits Chauffeurs.Algemeen
Public Sub New()
End Sub
Public Sub New(ByVal drv As DataRowView)
MyBase.New(drv(2), drv(1), drv(3), drv(4), drv(0)) '<--- error
occurs here
End Sub
In my form: huidigeChauffeur = New allePersonen.Chauffeurs.Yard(drv)
I'm 100% sure that in drv(4) there is a DBNull. But still I get the
error"Specified cast is not valid" even tho I use a nullable
Extra: If I type Cint(drv4) Ik get the error "Conversion from type
"DBNull" to type 'Integer' is not valid. Isn't this what a Nullable should
catch?!

No comments:

Post a Comment