Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Detecting null value on Integer
Message
De
30/01/2016 09:42:08
 
 
À
26/01/2016 13:12:10
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01630133
Message ID:
01630443
Vues:
52
>>But DataRow Items are Objects that must be cast to the relevant .NET type - and this can only be done if they are not DBNull.Value. So e.g:
dr("SomeString") = DBNull.Value
>>        Dim s As String
>>        If dr("SomeString") Is DBNull.Value Then
>>            s = Nothing
>>        Else
>>            s = CStr(dr("SomeString"))
>>        End If
(so s cannot be DBNull.Value)
>>If you're dealing with an integer data item in a DataRow you can test using:
dr.IsNull("SomeInt")
>
>I see in my code I am using it against a data row:
>
>
>                    ' Based on the type
>                    Select Case lcType
>
>                        ' Character, memo field, NVarChar, VarChar, VarChar(MAX), NVarChar(MAX)
>                        Case "C", "M", "O", "V", "X", "Y"
>
>                            ' If we have a null
>                            If oRow(lcField) Is DBNull.Value Then
>                                oRow(lcField) = ""
>                            End If
>
>
>I see the mentioned code for the string is not called by anything. So, that might explain the confusion.
>
>I do however have something like this:
>
>
>    ' Return True if a date is empty
>    ' expD1 Date
>    Public Function EmptyDate(ByVal tdDate As Object) As Boolean
>        Dim llEmpty As Boolean = False
>        Dim ldDate As Date
>
>        ' Based on the backend
>        Select Case nBackend
>
>            ' Visual FoxPro
>            Case 1
>                ldDate = New Date(1899, 12, 30)
>
>                ' If this is an empty date
>                If tdDate = ldDate Then
>                    llEmpty = True
>                End If
>
>                ' SQL Server
>            Case 2
>
>                ' If the date is null
>                If tdDate Is DBNull.Value Then
>                    llEmpty = True
>                End If
>
>                ldDate = New Date(1899, 12, 30)
>
>                ' If this is an empty date
>                If tdDate = ldDate Then
>                    llEmpty = True
>                End If
>
>                ' ODBC
>            Case 3
>
>        End Select
>
>        Return llEmpty
>    End Function
>
>
>Would you say the string explanation on null would also apply on a date? If yes, that would that make the above code obsolete?

Wouldn't this do the same job? :
   Public Function EmptyDate(ByVal tdDate As Object) As Boolean
        If tdDate Is DBNull.Value Then Return True
        Return CType(tdDate, Date) = New Date(1899, 12, 30)
    End Function
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform