Insert an image in a interbase blob field with c# and easysoft odbc

I have a table with a blob field (named imagen) where I want to save an image. I have odbc drivers for interbase (easysoft).
This is my code:

System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection("DSN=DBINMOV;UID=sysdba;PWD=masterkey");

System.Data.Odbc.OdbcCommand cmd = new System.Data.Odbc.OdbcCommand();

cmd.Connection = conn;

cmd.CommandText = "INSERT INTO graficos (codigo, pos, descripcion, imagen, cartel) VALUES ('00004', 77, 'prueba', :imagen, 'NO')";

cmd.Parameters.Add(":imagen", System.Data.Odbc.OdbcType.Binary);

System.IO.MemoryStream ms = new System.IO.MemoryStream();

pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

cmd.Parameters[":imagen"].Value = ms.GetBuffer();

conn.Open();

cmd.ExecuteNonQuery();

But my code doen't work! Same error always appear: ERROR [42S22] [easysoft] [Interbase] Dynamic SQL error, SQL error code = -206, Column unknown, IMAGEN

I'm sure than the column exists and I have written the columname correctly.
What I'm doing wrong?
iriemAsked:
Who is Participating?
 
TertioptusConnect With a Mentor Commented:
my objImage.Image that is being passed in, is of type byte[]
0
 
TertioptusCommented:
This is my command:       "INSERT INTO Images ([Image]) VALUES (?)";
Try OleDb as well as ODBC      

public int Update(int ID, cImage objImage)
            {

                  OleDbTransaction txn = (OleDbTransaction) this.m_htTransactions[ID];

                  m_cmdInsert.Transaction = txn;

                  OleDbParameter myParameter = new OleDbParameter("@Image", OleDbType.LongVarBinary, objImage.Image.Length);
                  myParameter.Value = objImage.Image;
                  m_cmdInsert.Parameters.Add(myParameter);

                  if(objImage.ImageID == sCodes.ID_Null)
                  {
                        m_cmdInsert.CommandText = "INSERT INTO Images ([Image]) VALUES (?)";

                        m_cmdInsert.ExecuteNonQuery();

                        m_cmdGetIdentity.Transaction = txn;

                        objImage.ImageID = Convert.ToInt32(m_cmdGetIdentity.ExecuteScalar());

                  }
                  else
                  {
                        m_cmdInsert.CommandText = "UPDATE Images SET [Image] = ? WHERE ImageID=" + objImage.ImageID.ToString();

                        m_cmdInsert.ExecuteNonQuery();
                  }

                  m_cmdInsert.Parameters.Clear();

                  return objImage.ImageID;
            }
0
 
iriemAuthor Commented:
It works!!! Thank you very much for your help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.