VB-to-Microsoft Access
Hi, I’ve save my profile info together with pictures. Why it didn’t show in my database (using Microsoft Access)? My pictures are set as OLE object in Microsoft Access
This is my VB codes:
Private Sub cmdSave_Click()
savePicToDB picPhoto.Tag, rsUser("Photo")
savePicToDB picFingerprint.Tag, rsUser("Fingerprint")
rsUser.AddNew
rsUser("Name") = txtname.Text
rsUser("IC No") = txtIC.Text
rsUser("Age") = txtAge.Text
rsUser("Gender") = txtGender.Text
rsUser("Contact No") = txtContact.Text
rsUser("Address") = txtAddress.Text
rsUser("Email") = txtEmail.Text
rsUser("Remarks") = txtRemarks.Text
rsUser.Update
txtBoxLock (True)
ctrlEnable (True)
cmdNew.SetFocus
End Sub
Public Sub savePicToDB(ByVal picFile As String, ByVal fldPic As ADODB.Field)
Dim bBLOB() As Byte
Dim iNum As Integer
If (picFile <> "") Then
iNum = FreeFile
Open picFile For Binary As #iNum
ReDim bBLOB(FileLen(picFile))
Get #iNum, , bBLOB
Close #1
' Store the BLOB
fldPic.AppendChunk bBLOB
End If
End Sub
Public Sub loadPicFromDB(ByVal fldPic As ADODB.Field, ByRef picTarget As PictureBox)
Dim sTempPic As String
Dim lImgSize As Long
Dim lOffset As Long
Dim bChunck() As Byte
Dim iFile As Integer
Const CHUNKSIZE = 1000
sTempPic = App.Path & "\temppic.jpg"
If Len(Dir(sTempPic)) > 0 Then
Kill sTempPic
End If
iFile = FreeFile
Open sTempPic For Binary As #iFile
lImgSize = fldPic.ActualSize
Do While lOffset < lImgSize
bChunck() = fldPic.GetChunk(CHUNKSIZE)
Put #iFile, , bChunck()
lOffset = lOffset + CHUNKSIZE
Loop
Close #iFile
If FileLen(sTempPic) > 0 Then
picTarget.Picture = LoadPicture(sTempPic)
Else
picTarget.Picture = Nothing
End If
Kill sTempPic
End Sub
Where is the problem??
Thanks so much!!