How to Store and Retrieve images in mySql or .mdb Database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rekedtechie
    New Member
    • Feb 2012
    • 51

    How to Store and Retrieve images in mySql or .mdb Database

    Hi, im about to create a program that can store images/pictures of employees..
    i saw a code before..
    dim variable as byte, appendChunk, and getChunk
    but i cant understand what is the logic behind this sequence..

    i can read these three ways of connection ADO, RDO or ADODC
    the rest im not familiar / i dont know..

    please post some codes and some explanation why/how this happens.. even if your data is in .mdb or sql database
    its ok, the only thing i need is to understand how it happens..

    Thanks! =)
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    The easiest way to save any file is converting it into a Byte() array and store it as a BLOB....

    Code:
        Public Function toArr(ByVal bm As Bitmap) As Byte()
            Dim ms As New System.IO.MemoryStream
            bm.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
            toArr = ms.GetBuffer
        End Function
        Public Function toImg(ByVal arr1() As Byte) As Bitmap
            Dim stream As New System.IO.MemoryStream(arr1)
            toImg = Image.FromStream(stream)
        End Function
    Here, I use this functions in VB.net; you shouldn't have much troble translating them into VB6.

    HTH

    Comment

    • rekedtechie
      New Member
      • Feb 2012
      • 51

      #3
      thanks for the info. sir! now i'll try to do this in vb6 then set a certain field on my database as blob data. =)

      Comment

      • rekedtechie
        New Member
        • Feb 2012
        • 51

        #4
        'as your code said..

        'to add
        Dim picByte() As Byte
        Dim strPath As String
        strPath=""& app.path &"/images/image1.jpg"
        Open strPath for Binary As #1
        ReDim picByte(0 to LOF(1))
        Get #1,,picByte()
        Close #1
        With rs
        .Requery
        .AddNew
        .Fields("name") = frmM.txtName.Te xt
        .Fields("Pic"). AppendChunk picByte()
        .Update
        End with

        'to view
        Set frmM.img1.DataS ource = rs
        frmM.img1.DataF ield = "Pic"

        'THANK YOU!! :D

        'now i'll try to save the string url instead of ole object. =)

        Comment

        • kadghar
          Recognized Expert Top Contributor
          • Apr 2007
          • 1302

          #5
          That'll certainly work too. And will make your query faster. Use this if you have small images and for some reason you want to give them higher level of security or encryption.

          Comment

          Working...