Bug #16617 MySqlBit crashes when trying to cast a bit field as bool
Submitted: 18 Jan 2006 21:16 Modified: 7 Mar 2006 22:33
Reporter: Jacob Cagley Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:mysql-connector-net-1.0.7 OS:Windows (Win2000)
Assigned to: Reggie Burnett CPU Architecture:Any

[18 Jan 2006 21:16] Jacob Cagley
Description:
public MySqlBit() : base()
{
	buffer = new byte[8];
	dbType = DbType..UInt64;
	mySqlDbType = MySqlDbType.Bit;
}

internal override Type SystemType
{
      get { return typeof( UInt64 ); } 

bool a = (bool) drow["Active"];

This is blow up in vs express 2005 c#

How to repeat:

pull a bit field from the database (Active) and cast it to bool

bool a = (bool) drow["Active"];

Suggested fix:
public MySqlBit() : base()
{
	buffer = new byte[8];
	dbType = DbType.Boolean; //.UInt64;
	mySqlDbType = MySqlDbType.Bit;
}

internal override Type SystemType
{
      get { return typeof( bool ); } 
}

If I change the types from UInt64 to bool, the code no longer crashes.
[7 Mar 2006 22:33] Reggie Burnett
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.mysql.com/documentation/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

Additional info:

 This is not a bug.  MySqlBit uses UInt64 as the system type since the bit data type can take a length <= 64 to indicate a bit field.  Certainly a bitfield of length <= 64 cannot be treated as a bool.   You have two choices.  On the reader object you can do .GetBoolean().  On a datarow you could do 

bool a = drow["Active"] == 1;
[6 May 2010 2:50] Alx g
And, what happen if I want to use Merge method to fill my DataTable??? Do I have to use a for??? It seems to me like there is somethin realy wrong with you guys... Sorry because I'm not good at english...