Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Handling DB Nulls
Message
From
29/12/2009 09:49:56
 
 
General information
Forum:
ASP.NET
Category:
Class design
Miscellaneous
Thread ID:
01440804
Message ID:
01441033
Views:
32
>FWIW, my general concern with the solutions in this thread is the basic concept of converting any DB nulls to default values. If the back-end allows nulls and exposes them in a dataset then surely they should continue to be treated as nulls in the front end. If, for example, you convert a null string to an empty string how do you determine what should be written back to the DB on an update.

And, FWIW, I agree with you Viv (and Mike). That's one of the things I mentioned to Kevin when he asked my opinion of Michel's code. I don't believe the DBNull.Value should be arbitrarily replaced with a Default value in the DataTable or the database (if the database allows NULLs). The only time I ever used those GetNonNull functions was for displaying values from a DataTable in a ListView (since ListViews are not databound).

So, in Kevin's case, perhaps he shouldn't be doing it either (it seems he's using a class object for databinding rather than the DataSets).

~~Bonnie

>
>
>>Of course null should not be confused with Empty(). They mean two different things.
>>
>>Have you really banished nulls from your database? There are times when a value truly is unknown, dates being a good example. I am more comfortable with calling the value null than using an arbitrary date such as 1900/01/01 to represent null.
>>
>>>Hi Kevin,
>>>
>>>for a different (non-code, data-oriented) take on this issue: null should not be confused with empty(). So say the relational gurus, and I agree: if it should not be empty, then that could occur anytime a user changes a value, so whether the DB accepts a null or not is irrelevant at that point. So, what I do is provide a default for all fields that corresponds to an "empty" value. For dates I use "1900/01/01 12:00 AM" which if I am hitting it from VFP, will also yield empty(), fortuitously. In other words, while the columns are all set to NOT NULL, I never have a NULL value. And therefore never run into the problems requiring a workaround. It's been in production at a hundred sites or so for a couple of years with no issues.
>>>
>>>Hank
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform