Checking Hashtable value for true false

  • Thread starter Thread starter Netmonster
  • Start date Start date
N

Netmonster

Hello,

Can someone tell me what I'm doing wrong? I am trying to check the
value of a hashtable and I know the value will be true or false. The
data is coming from a sql db column with bit as its datatype. If the DB
value is 0 the hashtable in a vs.net debug shows the value of {false}

Here is a piece of code. htData is a return from a sql query.
I have tried both

if(htData["linx"].Equals(0))
{
LabelError.Text = htData["linx"].ToString();
}
and
if(htData["linx"].Equals("false"))
{
LabelError.Text = htData["linx"].ToString();
}

Thanks in advanced,

KC
 
Hi Netmonster,

To make this work, you should do the following:

<code>
if(htData.ContainsKey("linx") && ((bool)htData["linx"]))
{
...
}
</code>

The problem being, when you are testing "if(htData["linx"].Equals(0))",
you are actually trying to test for an Int as opposed to a bool.

HTH,
~d
 
Back
Top