I use microsoft access.. How to store the picture in database and view the picture in Visual Basic? How to start?
Printable View
I use microsoft access.. How to store the picture in database and view the picture in Visual Basic? How to start?
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
Quote:
Originally Posted by matrik02
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
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?Quote:
Originally Posted by vksingh24
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
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
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
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?Code:Store all the images in a column of type OLE Object. You need to access it through ADO Stream Object
isn't the first method solved your problem?
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?
To go to next picuture you can use
vb Code:
adors.MoveNext
Are you showing it into two picturebox or one picture box
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
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"))
hi.. considering this post as resolved... but i would like to ask how to start this codes?