Access Database boolean and invalid cast

G

Guest

Access database column is set to true/false checkboxes
DataSet Table is set to boolean type

the following conditionals fail if the Access checkbox is "true" (i get invalid cast exceptions)

if ((bool)row["Resolved"]){...

if((bool)row["Resolved"]==true){...

if(row["Resolved"].ToString()=="True"){..

WHat the hell am i doing wrong????
thanks
 
M

Miha Markic [MVP C#]

Hi,

You might check that type the column really is and what data it holds:
object o = row["Resolved"];
then inspect o.
If the value is null you get an exception in your typecasting, also.

or check table.Columns["Resolved"].DataType to see the column's type.
 
M

Mary Chipman

One of the problems with Jet Yes/No fields (which I'm assuming your
checkboxes are based on) is that they aren't true Booleans, being also
able to contain null as well as t/f values. One way to get around this
is to not allow null values by always supplying a default value in the
table definition, and in your code always using zero (0) for
comparison purposes (zero is always false, everywhere).

--Mary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top