robintw
April 7th, 2008, 08:23 AM
Hi,
I am trying to insert a blob into a MySQL database using ODBC. I am using the OdbcCommand and OdbcParameter objects as suggested on many internet sites.
My code is below:
String^ CommandText = "INSERT INTO test (Data) VALUES (@Data);";
OdbcCommand^ cmd = gcnew OdbcCommand(CommandText, conn);
array<System::Byte>^ ByteArray = gcnew array<System::Byte>(2);
ByteArray[0] = 0xFF;
ByteArray[1] = 0xFF
OdbcParameter^ param = gcnew OdbcParameter("@Data", OdbcType::Image, 2);
param->Value = ByteArray;
cmd->Parameters->Add(param);
cmd->ExecuteNonQuery();
This code always gives the error "Column 'data' cannot be null'. This is correct as the column 'data' is defined as not allowing nulls - but it presumably means that somehow the byte array is not getting through to the parameter and then the database somehow.
Does anyone have any idea what is causing this, or how I could solve it?
Any help would be much appreciated,
Robin
I am trying to insert a blob into a MySQL database using ODBC. I am using the OdbcCommand and OdbcParameter objects as suggested on many internet sites.
My code is below:
String^ CommandText = "INSERT INTO test (Data) VALUES (@Data);";
OdbcCommand^ cmd = gcnew OdbcCommand(CommandText, conn);
array<System::Byte>^ ByteArray = gcnew array<System::Byte>(2);
ByteArray[0] = 0xFF;
ByteArray[1] = 0xFF
OdbcParameter^ param = gcnew OdbcParameter("@Data", OdbcType::Image, 2);
param->Value = ByteArray;
cmd->Parameters->Add(param);
cmd->ExecuteNonQuery();
This code always gives the error "Column 'data' cannot be null'. This is correct as the column 'data' is defined as not allowing nulls - but it presumably means that somehow the byte array is not getting through to the parameter and then the database somehow.
Does anyone have any idea what is causing this, or how I could solve it?
Any help would be much appreciated,
Robin