CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2006
    Posts
    31

    INSERT blob causing null error using ODBC

    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

  2. #2
    Join Date
    Sep 2007
    Posts
    82

    Re: INSERT blob causing null error using ODBC

    From looking at this I would think that the value you are setting for you param is invalid or nothing at all. My C/C++ is a bit rusty

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured