Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best Practices for a null field
Message
De
25/01/2006 12:15:25
 
 
À
25/01/2006 12:01:44
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB.NET 1.1
Database:
MS SQL Server
Divers
Thread ID:
01090093
Message ID:
01090144
Vues:
8
>Oh, and thanks for the help. I have seen the .tostring before, but never bothered to ask why they used it.

You're welcome. I'll pretty much always use .ToString() instead of casting a DataColumn value to a string. It's probably slower (although I don't know), but since it seamlessly handles the DBNull.Value, it's worth it to me.

Just as an FYI, what I've done for all data types is to create a static GetNonNull() method (with many overloads for different default datatypes) in a CommonMethods class. Then, depending on what I pass it as a default, it returns either the value of the object passed in, or the default if that object is DBNull.Value.

int i = CommonMethods.GetNonNull(MyDataRow["MyColumn"], 0);

The method will return a zero if MyColumn contains DBNull.Value but will return the value of the column otherwise.

~~Bonnie
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