Click here to Skip to main content
15,880,469 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: PathYetAnotherMakeUniqueName Pin
ShawnVN6-Apr-22 7:16
ShawnVN6-Apr-22 7:16 
GeneralNull Strikes Again! (even with C# special operators) Pin
raddevus22-Feb-22 11:25
mvaraddevus22-Feb-22 11:25 
GeneralRe: Null Strikes Again! (even with C# special operators) PinPopular
Jon McKee22-Feb-22 11:44
professionalJon McKee22-Feb-22 11:44 
GeneralRe: Null Strikes Again! (even with C# special operators) Pin
raddevus22-Feb-22 11:50
mvaraddevus22-Feb-22 11:50 
GeneralRe: Null Strikes Again! (even with C# special operators) Pin
raddevus22-Feb-22 11:53
mvaraddevus22-Feb-22 11:53 
GeneralRe: Null Strikes Again! (even with C# special operators) Pin
Paulo Zemek22-Feb-22 20:24
mvaPaulo Zemek22-Feb-22 20:24 
GeneralRe: Null Strikes Again! (even with C# special operators) Pin
Super Lloyd10-Mar-22 12:48
Super Lloyd10-Mar-22 12:48 
GeneralRe: Null Strikes Again! (even with C# special operators) Pin
jschell8-May-22 9:17
jschell8-May-22 9:17 
raddevus wrote:
I need to actually insert a System.DbNull.Value into the databse -- that's a true DBNull -- not the String null which the db chokes on.


That statement makes no sense.

Given a string/text value in a database it can have one of the following values.
1. Null
2. Empty string. Some databases do not allow this
3. Any other non-empty value.

That list does not include 'DBNull'.
The 'DBNull' value is usually a value that is intended as a stand in for results for the first item in the list above.

Perhaps your real problem is that you need to represent the following
1. A value that is not null
2. User did not 'choose' anything. So you need to represent 'no value', but you cannot use 'null'.

In the above you then use a magical value. If your database supports it and there NO chance it will be needed then an empty string can be used. But otherwise some nonsensical value is chosen.

For example say you need to provide a customer telephone number. So you allow numbers. But for your special value you allow 'xxx-xxx-xxxx'. Naturally you must special case the code.

HOWEVER, this is not an idea solution. And you should first examine the requirements that state that 'null' cannot be used in the first place. That the database does not allow it is NOT a argument for that. Because that to is just code and it must meet the needs of the business and not arbitrary developer opinions.
GeneralBuT cAn ThEY RuN DoOM? Pin
honey the codewitch7-Jan-22 6:14
mvahoney the codewitch7-Jan-22 6:14 
GeneralRe: BuT cAn ThEY RuN DoOM? Pin
jeron17-Jan-22 6:25
jeron17-Jan-22 6:25 
GeneralRe: BuT cAn ThEY RuN DoOM? Pin
honey the codewitch7-Jan-22 6:33
mvahoney the codewitch7-Jan-22 6:33 
GeneralRe: BuT cAn ThEY RuN DoOM? Pin
jeron17-Jan-22 6:43
jeron17-Jan-22 6:43 
GeneralRe: BuT cAn ThEY RuN DoOM? Pin
deepok14-Apr-22 5:44
deepok14-Apr-22 5:44 
GeneralRe: BuT cAn ThEY RuN DoOM? Pin
jeron14-Apr-22 5:53
jeron14-Apr-22 5:53 
GeneralRe: BuT cAn ThEY RuN DoOM? Pin
deepok14-Apr-22 5:58
deepok14-Apr-22 5:58 
GeneralRe: BuT cAn ThEY RuN DoOM? Pin
Alister Morton6-Apr-22 3:59
Alister Morton6-Apr-22 3:59 
GeneralRe: BuT cAn ThEY RuN DoOM? Pin
Super Lloyd7-Jan-22 11:56
Super Lloyd7-Jan-22 11:56 
GeneralRe: BuT cAn ThEY RuN DoOM? Pin
honey the codewitch7-Jan-22 12:17
mvahoney the codewitch7-Jan-22 12:17 
GeneralRe: BuT cAn ThEY RuN DoOM? Pin
Super Lloyd7-Jan-22 12:05
Super Lloyd7-Jan-22 12:05 
GeneralRe: BuT cAn ThEY RuN DoOM? Pin
Ron Anders7-Jan-22 14:57
Ron Anders7-Jan-22 14:57 
GeneralRe: BuT cAn ThEY RuN DoOM? Pin
David O'Neil11-Jan-22 14:07
professionalDavid O'Neil11-Jan-22 14:07 
GeneralRe: BuT cAn ThEY RuN DoOM? Pin
jsc4212-Jan-22 1:00
professionaljsc4212-Jan-22 1:00 
GeneralIntergalactic cephalopods Pin
honey the codewitch2-Jan-22 9:46
mvahoney the codewitch2-Jan-22 9:46 
JokeRe: Intergalactic cephalopods Pin
Joan M2-Jan-22 9:53
professionalJoan M2-Jan-22 9:53 
GeneralRe: Intergalactic cephalopods Pin
oofalladeez3432-Jan-22 10:10
professionaloofalladeez3432-Jan-22 10:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.