varbinary(max) to store an image.


Author
Message
Ross L Rooker, Sr.(1)
Ross L Rooker, Sr.(1)
StrataFrame User (236 reputation)StrataFrame User (236 reputation)StrataFrame User (236 reputation)StrataFrame User (236 reputation)StrataFrame User (236 reputation)StrataFrame User (236 reputation)StrataFrame User (236 reputation)StrataFrame User (236 reputation)StrataFrame User (236 reputation)
Group: StrataFrame Users
Posts: 50, Visits: 163
Getting this error:

An exception of type 'MicroFour.StrataFrame.Business.BusinessLayerException' occurred in MicroFour StrataFrame Business.dll but was not handled in user code. Additional information: An error occurred while refreshing the data from field 'tbvo_Groupi.GI_PICTURE' to property 'Image' on control 'pictureBox1.'  Are you missing FieldPropertyDescriptor for a custom property?

pictureBox1 is MicroFour.StrataFrame.UI.Windows.Forms.PictureBox

The GI_PICTURE column in a SQL table has the type: varbinary(max).

The BO tbvo_Groupi column GI_PICTURE has a type of System.Byte[]. The Custom Field Properties NULL Value Option is "Don't Allow Nulls". The box for "Use Custom Code" is checked. Here is the custom code:

[Browsable(false), BusinessFieldDisplayInEditor(), Description("GIpicture"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public System.Drawing.Bitmap GI_PICTURE
        {
            get
            {
                object loValue;
                loValue = this.CurrentRow["GI_PICTURE"];
                if (loValue == DBNull.Value)
                {
                    return new System.Drawing.Bitmap(1, 1);
                }
                else
                {
                    try
                    {
                        return (System.Drawing.Bitmap)this.BinaryFormatter.Deserialize(new System.IO.MemoryStream((Byte[])loValue));
                    }
                    catch
                    {
                        return new System.Drawing.Bitmap(1, 1);
                    }
                }
            }
            set
            {
                System.IO.MemoryStream loStream = new System.IO.MemoryStream();
                this.BinaryFormatter.Serialize(loStream, value);
                this.CurrentRow["GI_PICTURE"] = loStream.ToArray();
            }
        }


 



Reply
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
How was the data put into the field in the first place?  If the BinaryFormatter cannot deserialize the object, then I'm guessing that it's the raw bitmap data, right?  In that case, you need to change your custom property to the following:

      public System.Drawing.Bitmap GI_PICTURE
      {
         get
         {
            object value = this.CurrentRow["GI_PICTURE"];
            if(value is byte[])
            {
               return new System.Drawing.Bitmap(new System.IO.MemoryStream((byte[])value));
            }
            else
            {
               return new System.Drawing.Bitmap(1, 1);
            }
         }
         set
         {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            value.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
            this.CurrentRow["GI_PICTURE"] = ms.ToArray();
         }
      }

You may need to change the System.Drawing.Imaging.ImageFormat.Bmp to Jpeg or whatever format the data is stored in.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Ross L Rooker, Sr.(1) - 11 Years Ago
StrataFrame Team - 11 Years Ago
Ross L Rooker, Sr.(1) - 11 Years Ago
Ross L Rooker, Sr.(1) - 11 Years Ago
StrataFrame Team - 11 Years Ago
Ross L Rooker, Sr.(1) - 11 Years Ago
StrataFrame Team - 11 Years Ago
Ross L Rooker, Sr.(1) - 11 Years Ago
StrataFrame Team - 11 Years Ago
Ross L Rooker, Sr.(1) - 11 Years Ago
Ross L Rooker, Sr.(1) - 11 Years Ago
StrataFrame Team - 11 Years Ago
     YES!!!! Perfect.
Ross L Rooker, Sr.(1) - 11 Years Ago
             Awesome. Glad it's working for you :)
StrataFrame Team - 11 Years Ago
Ross L Rooker, Sr.(1) - 11 Years Ago
StrataFrame Team - 11 Years Ago
Ross L Rooker, Sr.(1) - 11 Years Ago
StrataFrame Team - 11 Years Ago
Ross L Rooker, Sr.(1) - 11 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search