Results 1 to 31 of 31

Thread: How to export / import Picture from Database?

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    37

    Question How to export / import Picture from Database?

    hello every body
    i want to know how to import and export picture from Database using DAO control?
    thanks

  2. #2
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: How to export / import Picture from Database?

    Suz

    My suggestion would be to NOT try to place a picture in a database.
    Instead, create a field called PicPath (or whatever) and place the file path there
    Then you can go to that record, get the path, and load the picture to wherever you need it.

    Spoo

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    37

    Re: How to export / import Picture from Database?

    Quote Originally Posted by Spooman View Post
    Suz

    My suggestion would be to NOT try to place a picture in a database.
    Instead, create a field called PicPath (or whatever) and place the file path there
    Then you can go to that record, get the path, and load the picture to wherever you need it.

    Spoo
    but the advantage of database is your picture is save and can't lose it..... i know it will take more space and maybe also picture loaded slow
    but i think it's better to use database

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to export / import Picture from Database?

    The DB FAQ: Database - How can I store images (or other files) in a database?

    Link uses ADO, but with little effort DAO can be used. ADO vs DAO? That's a different topic.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,853

    Re: How to export / import Picture from Database?

    Suzoki,

    You can stuff pictures into a memo field of a database. And there are several threads floating around in these forums on how to do that (some posted by me).

    However, two things. First, I'm assuming that you're thinking about some MS-Access database. If that's the case, don't forget that those file sizes are limited to 2GB. And that's still true of the latest MS-Access formats.

    Secondly, if/when you figure out how to get your pictures into the database, make sure it's done in some way that doesn't do Unicode expansion. Otherwise, each picture may wind up taking twice the space necessary to actually store it.

    Personally, I'd tend to use some Zip/Unzip technology rather than a database. Tanner has a nice set of ZIP-like compression algorithms in the codebank.

    If it's a static set of pictures, yet another alternative is to throw them into your project's resources, and then compile them into the EXE. Done that way, you're certain that they won't get lost.

    Good Luck,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: How to export / import Picture from Database?

    If memory serves you can bind a picture box to your DB and the process becomes very simple.

  7. #7

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    37

    Re: How to export / import Picture from Database?

    Quote Originally Posted by LaVolpe View Post
    The DB FAQ: Database - How can I store images (or other files) in a database?

    Link uses ADO, but with little effort DAO can be used. ADO vs DAO? That's a different topic.
    thanks i will try and tell you

  8. #8

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    37

    Re: How to export / import Picture from Database?

    Quote Originally Posted by Elroy View Post
    Suzoki,

    You can stuff pictures into a memo field of a database. And there are several threads floating around in these forums on how to do that (some posted by me).

    However, two things. First, I'm assuming that you're thinking about some MS-Access database. If that's the case, don't forget that those file sizes are limited to 2GB. And that's still true of the latest MS-Access formats.

    Secondly, if/when you figure out how to get your pictures into the database, make sure it's done in some way that doesn't do Unicode expansion. Otherwise, each picture may wind up taking twice the space necessary to actually store it.

    Personally, I'd tend to use some Zip/Unzip technology rather than a database. Tanner has a nice set of ZIP-like compression algorithms in the codebank.

    If it's a static set of pictures, yet another alternative is to throw them into your project's resources, and then compile them into the EXE. Done that way, you're certain that they won't get lost.

    Good Luck,
    Elroy
    thanks Elroy i will check that

  9. #9

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    37

    Re: How to export / import Picture from Database?

    Quote Originally Posted by DataMiser View Post
    If memory serves you can bind a picture box to your DB and the process becomes very simple.
    what you mean (memory serves)?

  10. #10
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: How to export / import Picture from Database?

    Quote Originally Posted by Suzoki View Post
    what you mean (memory serves)?
    He means his brain's memory, which may not be serving him well (he could be forgetting).

    I would not be storing images into the DB, unless it was a couple of minor small passport photos or such.
    I always have a sub folder in the same location as the DB.
    Your program knows where the DB is, so you don't even have to store the path to your images.
    You just have the name of the file (eg "mypicture01.jpg") in your DB, and your program can find it with both eyes closed.

    Rob

  11. #11
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,042

    Re: How to export / import Picture from Database?

    Quote Originally Posted by Spooman View Post
    Suz

    My suggestion would be to NOT try to place a picture in a database.
    Instead, create a field called PicPath (or whatever) and place the file path there
    Then you can go to that record, get the path, and load the picture to wherever you need it.

    Spoo
    +1 here, that's how I would do it also



    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  12. #12
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: How to export / import Picture from Database?

    A 2GB database can store 40,000 50KB images just by rough calculations. Call it 20,000 to be conservative.

    This means that in most cases you can safely ignore Chicken Little advice like that above. Unless you do something foolish like store uncompressed BMP format images you'll be fine. If they are compressed then a ZIP archive buys you nothing.

    If you are really planning to store larger quantities than that then sure, another strategy might make more sense.

  13. #13
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,042

    Re: How to export / import Picture from Database?

    Quote Originally Posted by dilettante View Post
    A 2GB database can store 40,000 50KB images just by rough calculations. Call it 20,000 to be conservative.

    This means that in most cases you can safely ignore Chicken Little advice like that above. Unless you do something foolish like store uncompressed BMP format images you'll be fine. If they are compressed then a ZIP archive buys you nothing.

    If you are really planning to store larger quantities than that then sure, another strategy might make more sense.
    so I'am a careful Chicken then

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  14. #14
    Frenzied Member
    Join Date
    Jun 2014
    Posts
    1,084

    Re: How to export / import Picture from Database?

    Quote Originally Posted by dilettante View Post
    A 2GB database can store 40,000 50KB images just by rough calculations. Call it 20,000 to be conservative.

    This means that in most cases you can safely ignore Chicken Little advice like that above. Unless you do something foolish like store uncompressed BMP format images you'll be fine. If they are compressed then a ZIP archive buys you nothing.

    If you are really planning to store larger quantities than that then sure, another strategy might make more sense.
    also,you can use more then 1 database at the same time
    if you are using access, what version ?
    from 2007 onward there is an attachment type, that compresses the file on loading and decompresses it on storing (if it is not already compressed)
    and makes it very simple to do so (loadfromfile and savetofile methods)
    https://msdn.microsoft.com/en-us/lib...ffice.12).aspx
    https://docs.microsoft.com/en-us/sql...ile-method-ado

    but i refrain from giving *any* advice
    do not put off till tomorrow what you can put off forever

  15. #15
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: How to export / import Picture from Database?

    Without knowing specifics it is hard to make recommendations. You can take the most clumsy solution as a one-size-fits-all it just might not be optimal for several reasons.

    For example storing the images as external files you can't directly use data binding any more. Of course it is quite possible to create your own UserControl supporting image data binding based on file names too.

    The biggest problem with using a bizarre private data type is lack of portability. That's why Microsoft discourages the use of ACCDB formats for anything but simple MS Access applications.

    The Access Database Engine 2010 Redistributable is not intended:

    1.As a general replacement for Jet (If you need a general replacement for Jet you should use SQL Server Express Edition).

    2.As a replacement for the Jet OLEDB Provider in server-side applications.

    3.As a general word processing, spreadsheet or database management system -To be used as a way to create files. (You can use Microsoft Office or Office automation to create the files that Microsoft Office supports.)

    4.To be used by a system service or server-side program where the code will run under a system account, or will deal with multiple users identities concurrently, or is highly reentrant and expects stateless behavior. Examples would include a program that is run from task scheduler when no user is logged in, or a program called from server-side web application such as ASP.NET, or a distributed component running under COM+ services.

  16. #16
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: How to export / import Picture from Database?

    Personally I like storing images in a database.

    1) Single suitcase for data and images aligns nicely with disaster recovery
    2) Images stored in a share can be inaccessible (permissions, hardware failures, AD problems - the list goes on)
    3) Mobile devices can get to the images without having to open additional holes in your firewall

    and I'm sure some more could be added to this list.

    Check this thread out - get down to post #35 for good info

    http://www.vbforums.com/showthread.p...-DB-datasource

    This will allow you to display the image WITHOUT a bound control and also without having to save it to disk first.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  17. #17
    Junior Member
    Join Date
    May 2017
    Posts
    22

    Re: How to export / import Picture from Database?

    Suzoki,
    1. will every record contain a pic?
    2. what size are the pics?
    Answer the above first. I'd suggest NOT storing the pics with the data unless they're small (~2-3KB each). Store the path to an image file instead.

  18. #18

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    37

    Re: How to export / import Picture from Database?

    Quote Originally Posted by Bob_too View Post
    Suzoki,
    1. will every record contain a pic?
    2. what size are the pics?
    Answer the above first. I'd suggest NOT storing the pics with the data unless they're small (~2-3KB each). Store the path to an image file instead.
    1- yes but totally picture not more 50
    2- size of picture not more 50 kb

  19. #19

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    37

    Re: How to export / import Picture from Database?

    Quote Originally Posted by LaVolpe View Post
    The DB FAQ: Database - How can I store images (or other files) in a database?

    Link uses ADO, but with little effort DAO can be used. ADO vs DAO? That's a different topic.
    i already use DAO so what's the code for this option
    i am already success to save picture to database but when i want to import to image i can't
    Code:
    Private Sub cmdAddPicture_Click()
    Dim BytData() As Byte
    If cmbPictureName.Text = "" Or Len(CommonDialog2.FileName) = 0 Then
        MsgBox "error", vbCritical, "error"
        Exit Sub
    End If
    Open CommonDialog2.FileName For Binary As #1
    ReDim BytData(FileLen(CommonDialog2.FileName))
    Get #1, , BytData
    Close #1
    F_P_P.AddNew
    F_P_P("Name") = cmbPictureName.Text
    F_P_P("Picture").AppendChunk (BytData)
    F_P_P.Update
    End Sub

  20. #20
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: How to export / import Picture from Database?

    but i refrain from giving *any* advice
    Chicken.

  21. #21
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: How to export / import Picture from Database?

    Your program knows where the DB is, so you don't even have to store the path to your images.
    You just have the name of the file (eg "mypicture01.jpg") in your DB, and your program can find it with both eyes closed.
    Really? Never knew one didn't need to include the path! I'm going to give THAT one a try.

  22. #22
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: How to export / import Picture from Database?

    OK Rob....I typed in a jpg filename into a short-text field in a table. The actual image is located in a sub directory to where the program is being run. Without putting in a pathname, I get the old 'can't find filename xxx'. So, can you explain the 'both eyes closed' comment?

    Code:
    cmd.CommandText = "Select * from newtablename"Set rs = cmd.Execute
    Picture1.Picture = LoadPicture(rs!pic)
    (error on last line, of course.

    Sammi

  23. #23
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: How to export / import Picture from Database?

    @sammi - I think you are missing the point here. If you CLOSE BOTH eyes you would never even see the error!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  24. #24
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: How to export / import Picture from Database?

    Quote Originally Posted by SamOscarBrown View Post
    Really? Never knew one didn't need to include the path! I'm going to give THAT one a try.
    You took it out of context ... by removing the line before "I always have a sub folder in the same location as the DB" ... so the Images folder is always in the same location as the DB... if you know where the DB is (and you should), then you know where the images folder is. With that you can build the path, no need to explicitly store it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  25. #25
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: How to export / import Picture from Database?

    Okay...in IDE mode, with pic in subdirectory or even in directory from which the project is run, I get the error.

    When in .EXE mode, it works when the file is in the same directory as the .exe file, but NOT if it is located in a sub (separate) directory.

    Is that what you meant...works if file is in .EXE directory when running in EXE mode???

  26. #26
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: How to export / import Picture from Database?

    Yeah....I miss a lot reading these posts, even with both eyes wide open!!!! Happens to all as we get older!

    Cute response, szl!

  27. #27
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: How to export / import Picture from Database?

    Quote Originally Posted by SamOscarBrown View Post
    Cute response, szl!
    Always happy to lend a hand!

    As useless as that might be sometime!!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  28. #28
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,042

    Re: How to export / import Picture from Database?

    Hi,

    well I supply always a INI-File with my Programs.
    Inifile starts with the first run and the Folder(s) must be selected (created)

    for Database Location (could be )Network
    for Helpfiles
    for Pictures
    for Backup Location

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  29. #29
    Frenzied Member
    Join Date
    Jun 2014
    Posts
    1,084

    Re: How to export / import Picture from Database?

    Quote Originally Posted by samoscarbrown View Post
    chicken.
    ! Rooster !
    do not put off till tomorrow what you can put off forever

  30. #30
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: How to export / import Picture from Database?

    Regarding "no need to store the path" -
    When the program loads, it gets the path to the DB, from an INI file
    My program stores that into a global string, say globPathToDB
    If the program is told to do something with say "Img001.jpg" it computes the path
    Code:
    Dim sPathAndFile as string
       sPathAndFile = globPathToDB & "Images/" & "Img001.jpg"
    Rob

  31. #31
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,042

    Re: How to export / import Picture from Database?

    Quote Originally Posted by Bobbles View Post
    Regarding "no need to store the path" -
    When the program loads, it gets the path to the DB, from an INI file
    My program stores that into a global string, say globPathToDB
    If the program is told to do something with say "Img001.jpg" it computes the path
    Code:
    Dim sPathAndFile as string
       sPathAndFile = globPathToDB & "Images/" & "Img001.jpg"
    Rob
    Hi Rob,
    I do it more or less the same way. I also use the main ID in the Form(Autoincrement of Mastertable) and
    format that as Picture ID to the Database table and it is saved to the FotoDirectory with that
    number

    here part of the Format..
    Code:
     ......
    Msg = "Foto in Archiv übernehmen ? "
              If vbYes = MsgBox(Msg, vbYesNo, "Foto") Then
             zFile = "VO_" & Format(txtNr, "000000") & _
                             Mid(FotoFileName, InStrRev(FotoFileName, "."))
         '    lblFoto.Caption = zFile
             txtFoto.Text = zFile
             On Error GoTo Fehler
             zFile = FotoDirectory & "\" & zFile
             Me.MousePointer = vbHourglass
             FileCopy FotoFileName, zFile
    ......
    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

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