Saving a picture from a file to the database

origami

Member
Licensed User
Hi all,

It's me again.

Here is another problem I have.

I have a "Person" table with a blob field for the picture of the person.
I created a form to enter the name of the person, and there is an Image field.
I added a contextual menu on this image to allow the user to load the image from a file.
So, in the code, I use a OpenDialog window (so that the user can select a picture file)

Here is the code :
B4X:
If ODPImage.Show <> cCancel Then
   Fichier = ODPImage.File
   ImgPBlob.Image = ODPImage.File
   FileClose (Fichier)
   strSQL = "Update personnes set P_Image = " & cmd.FileToBLOB(Fichier) & " Where P_ID = " & TBPID.Text
   cmd.CommandText = strSQL
   cmd.ExecuteNonQuery
End If

The problem is that I have an error message :
"The process cannot access the file '<__name_of_file_here__>' because it is being used by another process"

I tried to close the file (as you can see with the command FileClose), but it does not work.

And another extra question :
How do I remove a picture in the table ?
Is it :
B4X:
Update personnes set P_Image = NULL where . . .
or
B4X:
Update personnes set P_Image = '' where . . .
or
B4X:
Update personnes set P_Image = "" where . . .
or
B4X:
something else ??

Thanks a lot in advance.
 

willisgt

Active Member
Licensed User
In the original example at top, what type of objects are ODPImage and ImgPBlob?

Gary
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…