Pregunta

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?!

¿Fue útil?

Solución 2

Some person almost answered the question, but he/she removed the answer.

It's as following: drv.Row.Field(Of System.Nullable(Of Integer))(4).GetValueOrDefault

Otros consejos

To test for value if something could be null or nothing;

If NOT IsDbNull(drv(2)) AndAlso drv(2) = AnyValue Then
   'Do success
ELSE
   'Failure
End If
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top