Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
NULLS, checkboxes, CheckState
Message
 
 
To
16/01/2007 15:29:36
Alexandre Palma
Harms Software, Inc.
Alverca, Portugal
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
01186043
Message ID:
01186070
Views:
19
Wow, three great ideas in a matter of no time at all! Great to see the ,NET side has the same tenacity and knowledge of the VFP forums! *smile* I will try all of these out! Thank you so much!

JoeK

>Hi Joe try this
>
>if (System.Convert.IsDBNull(drPhone["allowlmtc"]))
>{
>    this.chkLMTC.CheckState = CheckState.Indeterminate;
>}
>else
>{
>    this.chkLMTC.Checked = (Boolean)drPhone["allowlmtc"];
>}
>
>
>
>>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
Previous
Reply
Map
View

Click here to load this message in the networking platform