Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Best Practices for a null field
Message
From
25/01/2006 12:15:25
 
 
To
25/01/2006 12:01:44
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB.NET 1.1
Database:
MS SQL Server
Miscellaneous
Thread ID:
01090093
Message ID:
01090144
Views:
9
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform