87
38
27
u/RavynousHunter Aug 13 '20
Oh god, the number of times I've been caught with my pants down using regular null instead of DBNull... I really wish that the connecting whatsis between .NET and the database would translate between the two automatically, because that's just annoying.
16
u/cordialgerm Aug 13 '20
Yeah System.DbNull is ridiculous
-2
Aug 13 '20
Now, if they named it something half-reasonable, like "NullaryDb", I might at least get the design of what they're trying to do. Realistically though, I get tired of catering to the "billion dollar mistake".
2
Aug 14 '20
Why am I getting downvoted?? Nullary objects are a popular and effective design pattern.
1
18
u/HTTP_404_NotFound bool isEven(int num) => num%2==0 Aug 12 '20
Technically, not a null check.
Normally a null check in .net can be either...
Value is null Or... Value == null
But, A dbnull is not actually null.
So, instead,
Isempty = Row[0].field == dbnull.value
22
9
1
u/transcriber_mu Nov 03 '20
Image Transcription: Code (C#)
bool temp = (string)line[3] == "On";
bool isRowEmpty = line[1].GetType().ToString() == "System.DBNull";
if (!isRowEmpty)[The cursor is hovering over GetType() and a pop-up hint displays "Type object.GetType()"]
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
0
97
u/KernowRoger Aug 12 '20
This is weirdness of SQL server where it returns a special type called DbNull instead of the value null. What you actually need to do is "is DbNull" against the value.