Results 1 to 14 of 14

Thread: [RESOLVED] Picture in databsase

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Resolved [RESOLVED] Picture in databsase

    I use microsoft access.. How to store the picture in database and view the picture in Visual Basic? How to start?

  2. #2
    Addicted Member
    Join Date
    Aug 2007
    Location
    India
    Posts
    141

    Re: Picture in databsase

    there is two way

    1) Store the path of the image in access file and store all your images in a directroy

    2) Store all the images in a column of type OLE Object. You need to access it through ADO Stream Object
    Do Good. Be Good. The World is yours.

  3. #3
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Picture in databsase

    Quote Originally Posted by matrik02
    I use microsoft access.. How to store the picture in database and view the picture in Visual Basic? How to start?

    RhinoBull has two links in signature:

    Save File To Database
    Extract File From Database

    But IMHO, you would be better of storing the path to the picture file instead.

    Here are a few other Links:
    http://www.vbforums.com/showthread.php?t=475765
    http://www.vbforums.com/showthread.php?t=482636
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: Picture in databsase

    Quote Originally Posted by vksingh24
    there is two way

    1) Store the path of the image in access file and store all your images in a directroy

    2) Store all the images in a column of type OLE Object. You need to access it through ADO Stream Object
    I have picture box and I named it as Picture1. How to access the path file of the image through ADO and view the image in Picture box? Have a sample to start?

  5. #5
    Addicted Member
    Join Date
    Aug 2007
    Location
    India
    Posts
    141

    Re: Picture in databsase

    Here is a very basic example

    vb Code:
    1. Private Sub Command1_Click()
    2. 'Reading from Database into PictureBox
    3.  
    4. If DE.CON.State = adStateClosed Then
    5.     DE.CON.Open
    6. End If
    7.  
    8. Dim adors As ADODB.Recordset
    9. Set adors = DE.CON.Execute("SELECT * from mypicTable")
    10. Picture1.Picture = LoadPicture(adors.Fields(0))
    11.  
    12. End Sub
    13.  
    14. Private Sub Command2_Click()
    15.  
    16. 'Saving Image Path into Directory
    17.  
    18. Dim myDirectory As String
    19. myDirectory = "C:\"
    20. cd1.Action = 1
    21. If Len(cd1.FileName) > 0 Then
    22.     Text1.Text = cd1.FileName
    23. End If
    24. If DE.CON.State = adStateClosed Then
    25.     DE.CON.Open
    26. End If
    27.  
    28. Dim adors As ADODB.Recordset
    29. Set adors = DE.CON.Execute("INSERT INTO myPicTable values('" & myDirectory & Right(cd1.FileName, (InStr(1, StrReverse(cd1.FileName), "\") - 1)) & "')")
    30. Picture1.Picture = LoadPicture(Text1.Text)
    31. SavePicture Picture1.Picture, "C:\" & Right(cd1.FileName, (InStr(1, StrReverse(cd1.FileName), "\") - 1))
    32.  
    33.  
    34. End Sub
    Do Good. Be Good. The World is yours.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: Picture in databsase

    I am interest with this code. I have field name and path name of the image store in this field name.My field name is "Picture". How I can access this field name? From the code,I don't see the column name to access the picture path location
    Code:
    Private Sub Command1_Click()'Reading from Database into PictureBox 
    If DE.CON.State = adStateClosed Then    
    DE.CON.Open End 
    If Dim adors As ADODB.Recordset
    Set adors = DE.CON.Execute("SELECT * from mypicTable")
    Picture1.Picture = LoadPicture(adors.Fields(0)) 
    End Sub

  7. #7
    Addicted Member
    Join Date
    Aug 2007
    Location
    India
    Posts
    141

    Re: Picture in databsase

    You can use the column name
    vb Code:
    1. Private Sub Command1_Click()'Reading from Database into PictureBox
    2. If DE.CON.State = adStateClosed Then    
    3. DE.CON.Open End
    4. If Dim adors As ADODB.Recordset
    5. Set adors = DE.CON.Execute("SELECT Picture from mypicTable")
    6. Picture1.Picture = LoadPicture(adors.Fields(0))
    7. End Sub
    Do Good. Be Good. The World is yours.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: Picture in databsase

    Code:
    Store all the images in a column of type OLE Object. You need to access it through ADO Stream Object
    I forgot to mention.. I try to familiar it by using OLE object . I set the field name data type as OLE Object. How to put the image on this field name?

  9. #9
    Addicted Member
    Join Date
    Aug 2007
    Location
    India
    Posts
    141

    Re: Picture in databsase

    isn't the first method solved your problem?
    Do Good. Be Good. The World is yours.

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: Picture in databsase

    Thank you so much.. I work. But I have two path location store in the column name. It work for one picture. How to go to the next picture and view it?

  11. #11
    Addicted Member
    Join Date
    Aug 2007
    Location
    India
    Posts
    141

    Re: Picture in databsase

    To go to next picuture you can use
    vb Code:
    1. adors.MoveNext

    Are you showing it into two picturebox or one picture box
    Do Good. Be Good. The World is yours.

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: Picture in databsase

    Why It only work for first record?I have path location in first and second record. I want to show the image into one picture box when I click next button. I would like to know what the number used for in this line LoadPicture(adors.Fields(0))?

    Code:
    Dim adors As ADODB.Recordset
    Private Sub Command1_Click()
    'Reading from Database into PictureBox
    
    If con.State = adStateClosed Then
        con.Open
    End If
    
    'Dim adors As ADODB.Recordset
    Set adors = con.Execute("SELECT Gambar from Penyakit_padi")
    Picture1.Picture = LoadPicture(adors.Fields(0))
    
    End Sub
    Last edited by matrik02; Sep 7th, 2007 at 03:36 AM.

  13. #13
    Addicted Member
    Join Date
    Aug 2007
    Location
    India
    Posts
    141

    Re: Picture in databsase

    Write the following code for the next button

    vb Code:
    1. Private Sub CommandNEXT_Click()
    2. 'Reading from Database into PictureBox
    3. adors.movenext
    4. Picture1.Picture = LoadPicture(adors.Fields(0))
    5. End Sub

    LoadPicture(adors.Fields(0))

    The no here is just the indicating the first column of the recodset, you can also write it
    vb Code:
    1. LoadPicture(adors.Fields("Gambar"))
    Do Good. Be Good. The World is yours.

  14. #14
    Addicted Member a-a06's Avatar
    Join Date
    Dec 2007
    Location
    P.H.
    Posts
    147

    Re: [RESOLVED] Picture in databsase

    hi.. considering this post as resolved... but i would like to ask how to start this codes?

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