|
-
Sep 7th, 2007, 12:02 AM
#1
Thread Starter
Frenzied Member
[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?
-
Sep 7th, 2007, 12:09 AM
#2
Addicted Member
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.
-
Sep 7th, 2007, 12:10 AM
#3
Re: Picture in databsase
 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."
-
Sep 7th, 2007, 01:55 AM
#4
Thread Starter
Frenzied Member
Re: Picture in databsase
 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?
-
Sep 7th, 2007, 02:20 AM
#5
Addicted Member
Re: Picture in databsase
Here is a very basic example
vb 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
Private Sub Command2_Click()
'Saving Image Path into Directory
Dim myDirectory As String
myDirectory = "C:\"
cd1.Action = 1
If Len(cd1.FileName) > 0 Then
Text1.Text = cd1.FileName
End If
If DE.CON.State = adStateClosed Then
DE.CON.Open
End If
Dim adors As ADODB.Recordset
Set adors = DE.CON.Execute("INSERT INTO myPicTable values('" & myDirectory & Right(cd1.FileName, (InStr(1, StrReverse(cd1.FileName), "\") - 1)) & "')")
Picture1.Picture = LoadPicture(Text1.Text)
SavePicture Picture1.Picture, "C:\" & Right(cd1.FileName, (InStr(1, StrReverse(cd1.FileName), "\") - 1))
End Sub
Do Good. Be Good. The World is yours.
-
Sep 7th, 2007, 02:30 AM
#6
Thread Starter
Frenzied Member
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
-
Sep 7th, 2007, 02:33 AM
#7
Addicted Member
Re: Picture in databsase
You can use the column name
vb 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 Picture from mypicTable")
Picture1.Picture = LoadPicture(adors.Fields(0))
End Sub
Do Good. Be Good. The World is yours.
-
Sep 7th, 2007, 02:48 AM
#8
Thread Starter
Frenzied Member
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?
-
Sep 7th, 2007, 02:59 AM
#9
Addicted Member
Re: Picture in databsase
isn't the first method solved your problem?
Do Good. Be Good. The World is yours.
-
Sep 7th, 2007, 03:09 AM
#10
Thread Starter
Frenzied Member
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?
-
Sep 7th, 2007, 03:24 AM
#11
Addicted Member
Re: Picture in databsase
To go to next picuture you can use
Are you showing it into two picturebox or one picture box
Do Good. Be Good. The World is yours.
-
Sep 7th, 2007, 03:32 AM
#12
Thread Starter
Frenzied Member
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.
-
Sep 7th, 2007, 03:44 AM
#13
Addicted Member
Re: Picture in databsase
Write the following code for the next button
vb Code:
Private Sub CommandNEXT_Click()
'Reading from Database into PictureBox
adors.movenext
Picture1.Picture = LoadPicture(adors.Fields(0))
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:
LoadPicture(adors.Fields("Gambar"))
Do Good. Be Good. The World is yours.
-
Jan 7th, 2008, 03:39 AM
#14
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|