1

在我的课堂上:

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

在我的表格中:huidigeChauffeur = New allePersonen.Chauffeurs.Yard(drv)

我 100% 确定在 drv(4) 中有一个 DBNull。但我仍然收到错误“指定的演员表无效”,即使我使用可空值

额外:如果我输入 Cint(drv4),我会收到错误“从“DBNull”类型转换为“Integer”类型无效。这不是 Nullable 应该捕获的吗?!

4

2 回答 2

0

测试某些东西是否可以为空或什么都没有的值;

If NOT IsDbNull(drv(2)) AndAlso drv(2) = AnyValue Then
   'Do success
ELSE
   'Failure
End If
于 2013-08-15T07:06:36.007 回答
0

有人几乎回答了这个问题,但他/她删除了答案。

如下: drv.Row.Field(Of System.Nullable(Of Integer))(4).GetValueOrDefault

于 2013-08-15T07:47:20.390 回答