Saving a picture from a file to the database

Discussion in 'Questions (Windows Mobile)' started by origami, Apr 27, 2008.

  1. origami

    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 :
    Code:
    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 :
    Code:
    Update personnes set P_Image = NULL where . . .
    or
    Code:
    Update personnes set P_Image = '' where . . .
    or
    Code:
    Update personnes set P_Image = "" where . . .
    or
    Code:
    something else ??
    Thanks a lot in advance.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Try to first save the image to the database and then show it.
    Code:
    If ODPImage.Show <> cCancel Then
       Fichier = ODPImage.File
       strSQL = 
    "Update personnes set P_Image = " & cmd.FileToBLOB(Fichier) & " Where P_ID = " & TBPID.Text
       cmd.CommandText = strSQL
       cmd.ExecuteNonQuery
            ImgPBlob.Image = ODPImage.File 
    End If
     
  3. origami

    origami Member Licensed User

    Yes, works like a charm !

    Thanks a lot !
     
  4. willisgt

    willisgt Active Member Licensed User

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

    Gary
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice