Adding Images to Database through PictureEdit


Author
Message
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
I threw a PictureEdit control on a Parts Maintenance form.  When navigating through the parts, the PictureEdit shows the stored image.  That's great...a simple binding maneuver.  If I choose to plant a new image into the PictureEdit control, it accepts it (via drag/drop, copy/paste, or load).  Wonderful.  I am happy with the part, so I click Save.  The image reverts back to the original image.  Apparently, I do not have something set correctly within the BO or on the control to allow for the image to be written back to the server.

Any ideas?

Thanks!
Bill

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
There is a post about that somewhere....specifically about the issue of it not saving. I'm looking for it.... Here is a related post that might help (or maybe not).



http://forum.strataframe.net/FindPost4739.aspx



This one might have some info:



http://forum.strataframe.net/FindPost2710.aspx



This is one is getting closer:



http://forum.strataframe.net/FindPost208.aspx



So, it may be that the pictureedit control is updating the image, but that image isn't getting saved (and serialized again) back to the datatable. You might have to take an extra step to get that done.
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Greg McGuffey (12/28/2007)
So, it may be that the pictureedit control is updating the image, but that image isn't getting saved (and serialized again) back to the datatable. You might have to take an extra step to get that done.

I have read through those posts.  I get an conversion error during compile that states that I am unable to convert from the byte[] type to the image type.  Not sure how the first post actually works when substituting the null value with the CType function.  Also, the whole concept of serializing the data doesn't seem quite appropriate in this situation.  The data flows beautifully from the database to the control (not serialized).  It is just the reverse that seems to be the issue.  I cannot change the image and persist it to the database.  The second thread suggest that the data be re-typed at the BO level (?) and serialized.  Well, wouldn't I get the same error if I tried to make a bitmap out of a byte[]?  The third thread comes across as Martian to me.  Sorry.

Any thoughts on what that "extra step" might be?  Sure would be nice to save images by simply binding the field to the control...like all other controls (textedit, comboedit, etc.).

Thanks a lot for the help, Greg!
Bill

Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Ok...after 1)  Adding reference to System.Drawing in the BO project; 2)  Setting the custom type for the image field to System.Drawing.Bitmap; 3)  Checking the serialize checkbox for the field; and 4) Building the BO with the partial build option; I get this new patch of code for my image field:

public System.Drawing.Bitmap sketch
{
    get
   
{
       
object loValue;
        loValue =
this.CurrentRow["sketch"];
       
if (loValue == DBNull.Value)
        {
           
return new System.Drawing.Bitmap(1, 1);
        }
       
else
       
{
           
try
           
{
               
return (System.Drawing.Bitmap)this.BinaryFormatter.Deserialize(new MemoryStream((Byte[])loValue));
            }
           
catch
           
{
               
return new System.Drawing.Bitmap(1, 1);
            }
        }
    }
   
set
   
{
       
MemoryStream loStream = new MemoryStream();
       
this.BinaryFormatter.Serialize(loStream, value);
       
this.CurrentRow["sketch"] = loStream.ToArray();
    }
}

I see now how the byte[] type is converted to a bitmap type.  Cool.  Smooooth  I am now following the code through to test the PictureEdit control on my form.  I have to tie up a few loose ends, first, though.


Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
No errors.  Just a plain, white box on all records.  Still not working.  I like the null replacement feature, though. 

Got more work to do on this. 

Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
I wiped out all customizations on the image field (SQL Server 2000).

I removed the PictureEdit control from the form.

...here's where it gets embarassing...

I added the SF PictureEdit control.  Everything works beautifully!  Just like I expected it to.

The problem stemmed from me having a newer version of the controls and I was too lazy when I first created the window to download the older version (DevEx 6.3.3).  In order to get the images to show up (not store), I used a BusinessBindingSource on the newer versioned PictureEdit control.  While it worked to show an image properly, it would not save it.

So, lesson learned.  Don't use a hammer and chisel to get the food out of your teeth, use a toothpick! Tongue

Bill

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search