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

Posted on 2006-06-06
Last Modified: 2007-12-19
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?
Question by:iriem
    LVL 5

    Expert Comment

    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;
    LVL 48

    Expert Comment

    LVL 5

    Accepted Solution

    my objImage.Image that is being passed in, is of type byte[]

    Author Comment

    It works!!! Thank you very much for your help!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now