| | |
Retrieve Image from Access DB to ImageControl in Form
![]() |
hi everyone, i have successfully saved the image file to DB by this code:
Private Sub cmdSave_Click()
Dim picsm As ADODB.Stream
Set picsm = New ADODB.Stream
picsm.Type = adTypeBinary
picsm.Open
picsm.LoadFromFile filepath
With rs
.AddNew
.Fields("Last") = txtLast.Text
.Fields("First") = txtFirst
.Fields("Pic") = picsm.Read
.Update
MsgBox "Successful"
End With
picsm.Close
Set picsm = Nothing
End Sub
But anyone can help me retrieve this image from DB and load it into the IMAGE CONTROL on the form?
i have this code:
Private Sub cmdSearch_Click()
Dim photo As String
squery = "select * from tblpic where Last='" & txtLast.Text & "'"
photo = rs.Fields("pic")
Set cm = New ADODB.Command
With cm
.ActiveConnection = conn
.CommandText = squery
.CommandType = adCmdText
End With
Set rs = New ADODB.Recordset
With rs
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockPessimistic
.Open cm
End With
With Me
.txtLast = rs!Last
.txtFirst = rs!First
.imgPic.Picture = LoadPicture(App.Path & "\pic\" & photo)
End With
End Sub
here is the error:
"file/path access error."
how could i retrieve the picture in the Access DB,
i think a folder must be reserved for the location of the photo.
thanks for the response.
Private Sub cmdSave_Click()
Dim picsm As ADODB.Stream
Set picsm = New ADODB.Stream
picsm.Type = adTypeBinary
picsm.Open
picsm.LoadFromFile filepath
With rs
.AddNew
.Fields("Last") = txtLast.Text
.Fields("First") = txtFirst
.Fields("Pic") = picsm.Read
.Update
MsgBox "Successful"
End With
picsm.Close
Set picsm = Nothing
End Sub
But anyone can help me retrieve this image from DB and load it into the IMAGE CONTROL on the form?
i have this code:
Private Sub cmdSearch_Click()
Dim photo As String
squery = "select * from tblpic where Last='" & txtLast.Text & "'"
photo = rs.Fields("pic")
Set cm = New ADODB.Command
With cm
.ActiveConnection = conn
.CommandText = squery
.CommandType = adCmdText
End With
Set rs = New ADODB.Recordset
With rs
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockPessimistic
.Open cm
End With
With Me
.txtLast = rs!Last
.txtFirst = rs!First
.imgPic.Picture = LoadPicture(App.Path & "\pic\" & photo)
End With
End Sub
here is the error:
"file/path access error."
how could i retrieve the picture in the Access DB,
i think a folder must be reserved for the location of the photo.
thanks for the response.
try the following sample code
vb Syntax (Toggle Plain Text)
Dim CN As New ADODB.Connection Dim RS As ADODB.Recordset Dim DataFile As Integer, Fl As Long, Chunks As Integer Dim Fragment As Integer, Chunk() As Byte, i As Integer, FileName As String Private Const ChunkSize As Integer = 16384 Private Const conChunkSize = 100 Private Sub Form_Load() CN.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Pubs;Data Source=Test" Dim strsql As String strsql = "SELECT * FROM pub_info where pub_id = '9999'" RS.Open strsql, CN, adOpenForwardOnly, adLockReadOnly ShowPic Set RS = Nothing Set RS = New Recordset End Sub Private Sub ShowPic() DataFile = 1 Open "pictemp" For Binary Access Write As DataFile Fl = RS!logo.ActualSize ' Length of data in file If Fl = 0 Then Close DataFile: Exit Sub Chunks = Fl \ ChunkSize Fragment = Fl Mod ChunkSize ReDim Chunk(Fragment) Chunk() = RS!logo.GetChunk(Fragment) Put DataFile, , Chunk() For i = 1 To Chunks ReDim Buffer(ChunkSize) Chunk() = RS!logo.GetChunk(ChunkSize) Put DataFile, , Chunk() Next i Close DataFile FileName = "pictemp" Picture1.Picture = LoadPicture(FileName) End Sub
Share your Knowledge.
![]() |
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Limiting Cursor VB6
- Next Thread: Use VB6 to read email in outlook
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






