Results 1 to 33 of 33

Thread: [Resolved] Picture in ACCESS

  1. #1

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Resolved [Resolved] Picture in ACCESS

    how can picture file can be stored in Access Database...

    ** Don't advice me
    i) to store path of file
    ii) it increases OHD
    iii) Bla Blah ...!!!!
    Last edited by vbPoet; Apr 20th, 2005 at 08:53 PM.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Picture in ACCESS

    Here is a sample procedure to store image:
    VB Code:
    1. Public Sub AddNewImage(rstTemp As ADODB.Recordset, _
    2.                        sTitle As String, sFileName As String)
    3. '=============================================================
    4. Dim file_num As String
    5. Dim file_length As Long
    6. Dim bytes() As Byte
    7. Dim num_blocks As Long
    8. Dim left_over As Long
    9. Dim block_num As Long
    10.  
    11. On Error GoTo ErrHandler
    12.  
    13.     rstTemp.Find "Title='" & sTitle & "'"
    14.    
    15.     file_num = FreeFile
    16.     Open sFileName For Binary Access Read As #file_num
    17.    
    18.     file_length = LOF(file_num)
    19.    
    20.     If file_length > 0 Then
    21.         num_blocks = file_length / BLOCK_SIZE
    22.         left_over = file_length Mod BLOCK_SIZE
    23.        
    24.         rstTemp("fImageSize") = file_length
    25.        
    26.         ReDim bytes(BLOCK_SIZE)
    27.         For block_num = 1 To num_blocks
    28.             Get #file_num, , bytes()
    29.             rstTemp("fImage").AppendChunk bytes()
    30.         Next block_num
    31.        
    32.         If left_over > 0 Then
    33.             ReDim bytes(left_over)
    34.             Get #file_num, , bytes()
    35.             rstTemp("fImage").AppendChunk bytes()
    36.         End If
    37.        
    38.         Close #file_num
    39.     End If
    40.    
    41.     rstTemp.Update
    42.    
    43.     Exit Sub
    44.  
    45. ErrHandler:
    46.  
    47.     Debug.Print Err.Description
    48.     Err.Clear
    49.     'Resume Next
    50.     Exit Sub
    51.  
    52. End Sub
    But KIM that storing PATH is a better approach, though.

  3. #3
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: Picture in ACCESS

    Regards,

    â„¢

    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  4. #4

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: Picture in ACCESS

    thx RhinO.
    from your code snippet i realise that .. with your same code any file can be stored in database like .exe,.jpg,.swf,.doc
    because you are first gaining binary access then appending this chunk into database ...
    M i right ..?

  5. #5

  6. #6

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: Picture in ACCESS

    Quote Originally Posted by RhinoBull
    Absolutely yes!
    The only problem is that MS Access is limited to 2GB ... but realistically after databse file reaches 1GB you will notice performance issues so frequently compacting mdb is highly preferable.

    thx deU & RhinO
    it means RhinO if we are using Oracle,mySQL then no Problem ..

  7. #7

  8. #8

    Thread Starter
    Fanatic Member vbPoet's Avatar
    Join Date
    Feb 2005
    Location
    Searching ..
    Posts
    669

    Re: Picture in ACCESS

    thx RhinO
    but unfortunately i cannot rate your post
    it says
    Spread your post any other place ( some thing like that )

  9. #9

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yodaâ„¢
    Posts
    60,710

    Re: [Resolved] Picture in ACCESS

    Hey RB, what is BLOCK_SIZE defined as? Nice code btw
    VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    • Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yodaâ„¢
    Posts
    60,710

    Re: [Resolved] Picture in ACCESS

    Oh, its a user defined const. Thanks.
    VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    • Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13

  14. #14
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: [Resolved] Picture in ACCESS

    This might have some importance with you....
    thx RhinO
    but unfortunately i cannot rate your post
    it says
    Spread your post any other place ( some thing like that )
    Why dont give me that rate instead?
    Regards,

    â„¢

    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  15. #15
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    488

    Re: [Resolved] Picture in ACCESS

    RhinoBull, since you seem to be a guru in that field, my question is primarily aimed at you .......

    I have a PictureBox filled with random colored pixels.

    SavePicture pic1.Image, "c:\test\test.bmp" worked great. So I can now save test.bmp into a database. But what if I wanted to skip that step, and save the PictureBox *DIRECTLY* into my database... Can that be done?

    I would appreciate to avoid saving the picture to disk first.

    Thanks
    Chris

  16. #16
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: [Resolved] Picture in ACCESS

    Quote Originally Posted by Krass
    ...I would appreciate to avoid saving the picture to disk first...
    Why? What's the problem with that? You save it to disk, then to your database and then delete the file if you wish not to keep it...

  17. #17
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    488

    Re: [Resolved] Picture in ACCESS

    Oh.. yes. This actually works great. Thanks.

    I just usually try to avoid unnecessary steps. Even tho I still believe there *should* be a way, I wouldn't even bother to change my code, at that point.

    Thank you
    Chris

  18. #18
    New Member
    Join Date
    Jan 2007
    Posts
    3

    Re: [Resolved] Picture in ACCESS

    RB! do you have any codes that can make commandbutton into xp style without using a user control/class module. API? thanks!

  19. #19

  20. #20
    New Member
    Join Date
    Jan 2007
    Posts
    3

    Re: [Resolved] Picture in ACCESS

    sorry. i forgot to think of the topic. but, if you still have something, hope you can share it. thanks!

  21. #21

  22. #22
    New Member
    Join Date
    Jan 2007
    Posts
    3

    Re: [Resolved] Picture in ACCESS

    ok. tnx rb!

  23. #23
    New Member
    Join Date
    May 2007
    Posts
    3

    Re: [Resolved] Picture in ACCESS

    Hi guys,
    do you know how can i use this code with vb2005?
    = RhinoBull's posted - The insertion pictor to database =

  24. #24

  25. #25
    New Member
    Join Date
    May 2007
    Posts
    3

    Re: [Resolved] Picture in ACCESS

    Thanks Rhino. But expected similar result, for vb.net, how i write the code?

  26. #26
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: [Resolved] Picture in ACCESS

    If I want to save the file or image to database
    What type of Data Type i should use ?

    Thanks for advice
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  27. #27
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    488

    Re: [Resolved] Picture in ACCESS

    hey nUflAvOrS..

    I use the "OLE Object" data type in my databases to store pictures......
    Chris

  28. #28

  29. #29
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: [Resolved] Picture in ACCESS

    Thanks Krass and RhinoBull, I will try your method.
    If got any problem i will ask the question here again.
    Thanks !
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  30. #30
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    519

    Re: Picture in ACCESS

    It isn't run, I sent to attachments file: http://www.mediafire.com/?j0kq1ityoch7r9i , can you help me ?


    Quote Originally Posted by RhinoBull View Post
    Here is a sample procedure to store image:
    VB Code:
    1. Public Sub AddNewImage(rstTemp As ADODB.Recordset, _
    2.                        sTitle As String, sFileName As String)
    3. '=============================================================
    4. Dim file_num As String
    5. Dim file_length As Long
    6. Dim bytes() As Byte
    7. Dim num_blocks As Long
    8. Dim left_over As Long
    9. Dim block_num As Long
    10.  
    11. On Error GoTo ErrHandler
    12.  
    13.     rstTemp.Find "Title='" & sTitle & "'"
    14.    
    15.     file_num = FreeFile
    16.     Open sFileName For Binary Access Read As #file_num
    17.    
    18.     file_length = LOF(file_num)
    19.    
    20.     If file_length > 0 Then
    21.         num_blocks = file_length / BLOCK_SIZE
    22.         left_over = file_length Mod BLOCK_SIZE
    23.        
    24.         rstTemp("fImageSize") = file_length
    25.        
    26.         ReDim bytes(BLOCK_SIZE)
    27.         For block_num = 1 To num_blocks
    28.             Get #file_num, , bytes()
    29.             rstTemp("fImage").AppendChunk bytes()
    30.         Next block_num
    31.        
    32.         If left_over > 0 Then
    33.             ReDim bytes(left_over)
    34.             Get #file_num, , bytes()
    35.             rstTemp("fImage").AppendChunk bytes()
    36.         End If
    37.        
    38.         Close #file_num
    39.     End If
    40.    
    41.     rstTemp.Update
    42.    
    43.     Exit Sub
    44.  
    45. ErrHandler:
    46.  
    47.     Debug.Print Err.Description
    48.     Err.Clear
    49.     'Resume Next
    50.     Exit Sub
    51.  
    52. End Sub
    But KIM that storing PATH is a better approach, though.

  31. #31

  32. #32
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    519

    Re: [Resolved] Picture in ACCESS

    The compress this file, this is example for yourself, the subject pictures insert into database and picture load from database up PictureBox or Image are very rare. I was copy your source code in VB6.0 and try run but it is not, so ask you. I want to know directions for use and declare. If i know, i never ask you.

  33. #33
    Addicted Member
    Join Date
    Mar 2009
    Posts
    244

    Re: [Resolved] Picture in ACCESS

    If you need to store a picture into your database and want to read it directly into a picturebox (or any Picture(IPictureDisp) property) without first having to write the image to the tempfolder(or any folder) and use loadimage, you can use the propertybag... I found this method somewhere and I found it ingenius use of VB specific methods:

    Field ImageData is of varbinary type.
    Code:
    Private Const csPropertyBagNameImageData As String = "ImageData"
    
    Private property_picPicture As IPictureDisp
    
    Private Sub ReadRecord(ByVal rs As RecordSet)
       Dim abBuffer()  As Byte
       Dim PB          As PropertyBag
    
          If IsNull(rs.Fields!ImageData) Then
            Set property_picPicture = Nothing
          Else
            abBuffer() = rs.Fields!ImageData
            Set PB = New PropertyBag
            PB.Contents = abBuffer()
            Set property_picPicture = PB.ReadProperty(csPropertyBagNameImageData)
            Set PB = Nothing
          End If
    End Sub
    
    Private Sub pWriteRecord(ByVal rs As RecordSet)
      Dim PB  As PropertyBag
        If property_picPicture Is Nothing Then
          rs.Fields!ImageData = Null
        Else
          Set PB = New PropertyBag
          Call PB.WriteProperty(csPropertyBagNameImageData, property_picPicture)
          rs.Fields!ImageData = PB.Contents
          Set PB = Nothing
        End If
        Call rs.Update
    End Sub
    The above code only has problems with image of ICON type, which will not have it's transparency anymore and the palet is fubar, but I never bothered YET to find a solution for that..

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width