[Mono-list] Cast a char(1) to a boolean

Nick Loeve mono@trickie.org
Sun, 24 Oct 2004 10:39:15 +1000


> Thanks for your replys.  I'm still having a problem.  Here is a code 
> snippit:
>                ds = dbManager.GetState(ref conn);
>                dt = ds.Tables[0];
>                foreach (DataRow dr in dt.Rows)
>                {
>                    if ((char)dr[ "running"] == 'T')
>                    {
>                        this.ProcessRecords(dr);
>                    }
>                }
> ds is a DataSet, dt is a DataTable and the value is being returned in 
> an object of  type DataRow.  If I run it I get the runtime error:
> Unhandled Exception: System.InvalidCastException: Cannot cast from 
> source type to destination type.

Is it this line causing the problems?

> if ((char)dr[ "running"] == 'T')

I would try using an integer to determine true/false. You can use the 
tinyint(1) field type and use 1 or 0 to determine true false. IMHO it 
is better than coming up with a char based scheme for determining true 
or false.