CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2001
    Location
    County Durham, England
    Posts
    238

    Saving a Bitmap,Gif or JPEG Image to an Access 2000 Database

    Can somebody help me with this one,

    How do you save the contents of the Image Control as an embedded image in an Access 2000 database table, I've tried all weekend and just cannot work it out ?

    help !


  2. #2
    Join Date
    Mar 2001
    Posts
    4

    Re: Saving a Bitmap,Gif or JPEG Image to an Access 2000 Database

    using the ado objects appendchunk method
    for example:
    strfilename is jpg file name
    flddestination is field in the database

    Function CopyLargeField(strfilename As String, fldDestination As Field)
    Dim strchunk As String * 1024
    Open strfilename For Input As #1
    Do While Not EOF(1)
    Input #1, strchunk
    fldDestination.AppendChunk strchunk
    strchunk = ""
    Loop
    Close #1
    End Function
    Its is available in the Msdn library in different way.


  3. #3
    Join Date
    Mar 2001
    Location
    County Durham, England
    Posts
    238

    Re: Saving a Bitmap,Gif or JPEG Image to an Access 2000 Database

    Is this not just saving the Filename of where the image is stored ?, I need to save the actual Image as an OLE object in the Database as various employees will be using this database and saving images, so one employee saves an image from his local drive, another employee needs to be able to open the image.

    will this code achieve this as it looks like its just savinf strings?


  4. #4
    Join Date
    Mar 2001
    Posts
    4

    Re: Saving a Bitmap,Gif or JPEG Image to an Access 2000 Database

    'Opening the access database connection
    'Here the student database is a sample database
    'two fields firstname and photo.
    'the photo field data type being ole object
    'while firstname is simple text
    Private Sub Form_Load()
    Set adoconn = New ADODB.Connection
    With adoconn
    .ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Users\Sheshu\misc\db1.mdb"
    .CursorLocation = adUseClient
    .Open
    End With
    Set adors = New ADODB.Recordset
    adors.CursorType = adOpenKeyset
    adors.LockType = adLockOptimistic
    adors.Open "students", adoconn, , , adCmdTable
    End Sub
    'In this click event getting the jpeg file path Private Sub Command1_Click()

    With cdlgphoto
    .CancelError = False
    .Filter = "All Files [*.jpg]|*.jpg"
    .ShowOpen
    strfilename = .FileName
    End With
    End Sub
    'Here inserting into the database
    Private Sub Command2_Click()
    On Error GoTo errhandler
    adors.AddNew
    adors.Fields!firstname = Text1.Text
    CopyLargeField strfilename, adors!photo
    adors.Update
    Exit Sub
    errhandler:
    MsgBox Err.Number + Err.Description
    End Sub
    Function CopyLargeField(strfilename As String, fldDestination As Field)
    Dim strchunk As String * 1024
    Open strfilename For Input As #1
    Do While Not EOF(1)
    Input #1, strchunk
    fldDestination.AppendChunk strchunk
    strchunk = ""
    Loop
    Close #1
    End Function
    'The above code is inserting into database
    'My problem was retrieving from database and showing on the UI.


  5. #5
    Join Date
    Mar 2001
    Location
    Florida
    Posts
    2

    Re: Saving a Bitmap,Gif or JPEG Image to an Access 2000 Database

    I would reserve a place on your server to store the image files. Access get big quickly and you might have performance issues later. We placed code in our form to display the image associated to an index. the pictures are stored ie: 1.bmp,2.bmp ect. when the form is opened it reives the picture or you can do the same thing in a report

    Private Sub pic_number_GotFocus()
    On Error GoTo ERRpic_number_GotFocus:

    Image8.Picture = "C:\AAA\outside projects\" & [pic_number] & ".jpg"

    Exit Sub

    ERRpic_number_GotFocus: Image8.Picture = "C:\AAA\outside projects\" & 1009 & ".jpg"
    End Sub




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured