“Conversion from type 'DBNull' to type 'Boolean' is not valid”, after checking that it's not DBNull

StackOverflow https://stackoverflow.com/questions/8913447

In my ASP.Net Web-Application, I'm getting this error:

Conversion from type 'DBNull' to type 'Boolean' is not valid.

From this function:

Namespace atc
    Public Class Nil
        '...
        Public Shared Function Bool(ByVal Item As Object) As Boolean
            Return IIf(Item IsNot Nothing AndAlso Not IsDBNull(Item), CBool(Item), False)
        End Function
        '...
    End Class
End Namespace

As you can see, I'm explicitly checking if Item is DBNull, and if it is then I return False.

The error does not occur when Item is not DBNull, so I don't understand why this is happening.

没有正确的解决方案

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top