[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 791
  • Last Modified:

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();



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?
  • 2
1 Solution
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;

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


                        m_cmdGetIdentity.Transaction = txn;

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

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



                  return objImage.ImageID;
my objImage.Image that is being passed in, is of type byte[]
iriemAuthor Commented:
It works!!! Thank you very much for your help!

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now