Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Use of question mark in parameters
Message
De
09/11/2011 10:48:01
 
 
À
09/11/2011 10:24:56
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01528240
Message ID:
01528487
Vues:
33
>>Not sure I understand that. If they're initialized to an empty value then how can they ever be null? I also wonder about the comparison you were doing to DBNull.Value ... I don't believe you can compare a string to DBNull.Value. Well, not in C# anyway ... maybe VB is more lax about that?
>
>The method initializes a local variable to empty. But, the parameter received maybe null, empty or contains a value. Thus, in the method, I only need to verify if it is not null. If that is the case, then the variable is set to it.


OK, I guess I misunderstood what you said before. Thanks for clarifying. However, your original code is not checking for the string to be null. You had this:
        Public Function GetNonNullable(ByVal tcValue As String) As String
            Dim lcValue As Integer = ""

            ' If we have a value
            If Not tcValue Is DBNull.Value Then
                lcValue = tcValue
            End If

            Return lcValue
        End Function
Checking for DBNull.Value is NOT the same thing as checking for null! In fact, in C# the above comparison cannot even be made. I think what you actually want to compare is whether it's equal to null (assuming I've gotten the VB syntax correct):
        Public Function GetNonNullable(ByVal tcValue As String) As String
            Dim lcValue As Integer = ""

            ' If we have a value
            If Not tcValue = null Then
                lcValue = tcValue
            End If

            Return lcValue
        End Function
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform