Hi,
if the Value of a MySQLParameter is of type Boolean,
Value.ToString() -- i.e. "True" or "False" (quotes not
included) -- is going to be inserted in the SQL command
sent to the MySQL server, which is then going to choke
whatever is the column type. This faulty behaviour is
the consequence of the default statement in the switch
of MySQLParameter.SerializeToBytes:
parm_string = Value.ToString();
It works fine for integral and floating-point values
but not for boolean ones for the reason explained
above. A simple solution seems to test for that special
case. For example, by replacing
default:
parm_string = Value.ToString();
break;
with
default:
if(Value.GetType() == typeof(Boolean))
{
switch(m_dbType)
{
case MySQLDbType.Enum:
parm_string = (bool)Value ? "1" : "2";
break;
case MySQLDbType.Byte:
case MySQLDbType.Decimal:
case MySQLDbType.Double:
case MySQLDbType.Float:
case MySQLDbType.Int24:
case MySQLDbType.Long:
case MySQLDbType.Short:
parm_string = (bool)Value ? "1" : "0";
break;
default:
StringBuilder b = new StringBuilder();
b.AppendFormat("Cannot store a boolean value into
a column of type {0} without explicit conversion",
m_dbType);
throw new MySQLException(b.ToString());
}
}
else
{
parm_string = Value.ToString();
}
Hth,
--
Luc Bourhis
Logged In: YES
user_id=523261
I'll get to this in a day or two. Thanks