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

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

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?
0
iriem
Asked:
iriem
  • 2
1 Solution
 
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
 
TertioptusCommented:
my objImage.Image that is being passed in, is of type byte[]
0
 
iriemAuthor Commented:
It works!!! Thank you very much for your help!
0

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