Version Compatibility: Visual Basic.NET
More information: Check for DBNull in VB.NET, with optional specification of type, so it converts null to the appropriate value (e.g., "" for string, 0 for numbers).
Instructions: Copy the declarations and code below and paste directly into your VB project.
Enum enumObjectType
StrType = 0
IntType = 1
DblType = 2
End Enum
Public Function CheckDBNull(ByVal obj As Object, _
Optional ByVal ObjectType As enumObjectType = enumObjectType.StrType) As Object
Dim objReturn As Object
objReturn = obj
If ObjectType = enumObjectType.StrType And IsDBNull(obj) Then
objReturn = ""
ElseIf ObjectType = enumObjectType.IntType And IsDBNull(obj) Then
objReturn = 0
ElseIf ObjectType = enumObjectType.DblType And IsDBNull(obj) Then
objReturn = 0.0
End If
Return objReturn
End Function
0 comments:
Post a Comment