Page 1 of 1

CAST to binary not working

Posted: Thu 25 Aug 2005 16:35
by qnguyen
I have a tinyblob column that I want to insert binary data into it( a guid)

I create a MySqlCommand using parameter is follow

INSERT INTO MY_TABLE (IDCol) Values (CAST(0xCE2A0AA8D33211D79C4800A0CC40804D AS BINARY))

but when I look in the table, the data is just insert as text

0xCE2A0AA8D33211D79C4800A0CC40804D

Anyone know how to make it insert as binary?

Thanks.

Posted: Thu 25 Aug 2005 18:15
by qnguyen
look like the driver put single quote around my value
because the parameter type is default to varchar.

'0xCE2A0AA8D33211D79C4800A0CC40804D'

Is there a way to tell it to not put single quote around the value?

thanks.

Posted: Fri 26 Aug 2005 06:42
by Serious
You have to use parameters.

Code: Select all

MySqlCommand command = new MySqlCommand("insert into my_table(f_tinyblob) values (:blob)", connection);

byte [] data;
...
command.Parameters.Add("blob", data);
command.ExecuteNonQuery();