Saving Graphic Image to Access Database? 
Author Message
 Saving Graphic Image to Access Database?

Hi All,
I have a problem saving a picture in a Picture Box to an Access Database.

I made the access database field of type  OLE OBJECT.
I try to take a picture and  save it to this field by writing:
    Table!Pic = PictureBox.Picture

I have also tried a number of other ways as well but keep getting errors
mostly complaining about data types.

The odd thing is that I can accomplish this task easily by using a Data
Object (such as DA0 Record Object) and Binding the Picture Box to the Field
in the database.  I don't want to Bind anything if I can help it.

Any suggestions would be greatly appreciated.
Thanks,
John.



Sun, 16 Sep 2001 03:00:00 GMT  
 Saving Graphic Image to Access Database?
Hi John,

Try This:

Look at this:

  Dim pBag As PropertyBag
  Dim pByteA() As Byte 'Array for raw data

  Dim lRecCount As Long
  Dim i As Integer

  dbData.Recordset.MoveLast
  lRecCount = dbData.Recordset.RecordCount
  dbData.Recordset.MoveFirst

  Select Case Index
    Case 0 'Attach
        For i = 1 To lRecCount
            picToAttach.Picture = LoadPicture("I:\PUBLI\WINLOGOS\BMP16\" &
dbData.Recordset!File_Name & ".BMP")

            'Create propertybag
            Set pBag = New PropertyBag

            'Write object
            pBag.WriteProperty "MyPicture", picToAttach.Picture

            'Fill array with binary data of pic
            pByteA = pBag.Contents

            'Assign raw data to OLE Object field of MDB
            dbData.Recordset.Edit
            dbData.Recordset.Fields("Embedded_Pic").Value = pByteA
            dbData.Recordset.Update
            dbData.Recordset.MoveNext

            DoEvents
        Next i

    Case 1 'Test
        For i = 1 To lRecCount
            pByteA = dbData.Recordset.Fields("EMBEDDED_PIC").Value
            Set pBag = New PropertyBag
            pBag.Contents = pByteA
            Set picToAttach = pBag.ReadProperty("MyPicture")
            dbData.Recordset.MoveNext
            DoEvents
        Next i



Quote:
>Hi All,
>I have a problem saving a picture in a Picture Box to an Access Database.

>I made the access database field of type  OLE OBJECT.
>I try to take a picture and  save it to this field by writing:
>    Table!Pic = PictureBox.Picture

>I have also tried a number of other ways as well but keep getting errors
>mostly complaining about data types.

>The odd thing is that I can accomplish this task easily by using a Data
>Object (such as DA0 Record Object) and Binding the Picture Box to the Field
>in the database.  I don't want to Bind anything if I can help it.

>Any suggestions would be greatly appreciated.
>Thanks,
>John.



Sun, 16 Sep 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Saving Graphic Image to Access Database?

2. Saving Graphic Image to Access Database?

3. Saving Graphic Image to Access Database?

4. How to save my drawing graphic as image???i did load from image

5. How to save and load images to/from Access Database

6. Saving Images in Access database

7. Select an image from Access Database and then save it in disk

8. help:How to Load/Save image or voice for ACCESS DATABASE in Visual Basic

9. Save Image object to Access Database

10. Saving image of a control to a graphic..

11. Saving graphic image to VB Memo field

12. Need Control or DLL to save images in many different graphic formats

 

 
Powered by phpBB® Forum Software