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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

Update image field (blob)

I have this code:

            System.IO.FileStream fs = new System.IO.FileStream(@"C:\Inetpub\wwwroot\btech\frontend\btech_FR\" + flname + ".HTM", System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
            byte[] rawData = br.ReadBytes((int)fs.Length);
            br.Close();
            fs.Close();

            OdbcCommand cm;
            string query = "UPDATE ViewArtikels SET Attachment= ? WHERE ItemCode='"+ fl +"' and Lang='FR'";
            cm = new OdbcCommand(query, conn);
            cm.Parameters.Add("", OdbcType.Binary, rawData.Length, fldname).Value = rawData;
            cm.ExecuteNonQuery();


On the last line i get following error: Invalid precision value

Any idea how cum?
0
secuteamers
Asked:
secuteamers
  • 4
  • 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;
          }

my objImage.Image that is being passed in, is of type byte[]
0
 
TertioptusCommented:
For updates:


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

m_cmdInsert.ExecuteNonQuery();

my objImage.Image that is being passed in, is of type byte[]
0
 
secuteamersAuthor Commented:
only need odbc solution.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
TertioptusCommented:
           cm.Parameters.Add("", OdbcType.Binary, rawData.Length, fldname).Value = rawData;

         string query = "UPDATE ViewArtikels SET Attachment= ? WHERE ItemCode='"+ fl +"' and Lang='FR'";

instead try:

               OdbcParameter myParameter = new OdbcParameter("@Attachments", OdbcType.Binary, rawData.Length);
               myParameter.Value = rawData;
               cm.Parameters.Add(myParameter);

         string query = "UPDATE ViewArtikels SET [Attachment]= ? WHERE ItemCode='"+ fl +"' and Lang='FR'";
0
 
secuteamersAuthor Commented:
still getting the error "Invalid precision value"
0
 
TertioptusCommented:
try OdbcType.VarBinary
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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