Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
NULLS, checkboxes, CheckState
Message
From
16/01/2007 15:17:02
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
01186043
Message ID:
01186050
Views:
24
Hi Joe,

As a start, you could use the DataRow.IsNull() method to perform your initial comparison.

Bill

>Hey all,
>
>I have a bit field in SQL Server that allows NULLs. In fact, it NEEDS to allow nulls, because I want to know if the field is yes, no, or indeterminate. Imagine my glee when I saw that .NET checkboxes can have an "indeterminate" state!
>
>My glee vanished quickly when I tried to read what was in the column in order to set the checkbox to true, false, or indeterminate. First off, a Boolean cast does not work when the column is null. Also, at run-time the debugger does not show it as null, it shows it as "{}". What the heck is "{}"? Empty? Null? Zero?
>
>So, when I try the "if" statement:
>
>
>if (drPhone["allowlmtc"] == null)
>{
>    this.chkLMTC.CheckState = CheckState.Indeterminate;
>}
>else
>{
>    this.chkLMTC.Checked = (Boolean)drPhone["allowlmtc"];
>}
>
>
>(drPhone is a DataRow object, "allowlmtc" is the field that allows true/false/null).
>
>The compiler lets it through, but the "else" portion gets called even when the "allowlmtc" column is a null. If I try to put a Boolean cast on the column right away, I get the same error. Like I said, the drPhone.["allowlmtc"] expression shows as "{}" in the debugger. What the heck kind of value is that? What will both the compiler and run-time allow?
>
>I can tell you that:
>
>
>if (drPhone["allowlmtc"].ToString().Length == 0)
>
>
>works, and the checkbox visually displays as I would like it to. But, man, what a kludge! It is frustrating not even knowing what exactly the null expression's data type is, and the fact that I can't even compare it to null at run-time and get an accurate result.
>
>Any ideas on how to make this more elegant? I am trying to learn the "right" way to exist in the C# world coming from a Visual Foxpro background. Any and all help/ideas/suggestions/scoldings are welcome. *smile*
>
>Thanks,
>JoeK
William A. Caton III
Software Engineer
MAXIMUS
Atlanta, Ga.
Previous
Reply
Map
View

Click here to load this message in the networking platform