Questions

Uploading jpeg picture to ms access via Visual basic 6

Tags:
+
0 Votes
Locked

Uploading jpeg picture to ms access via Visual basic 6

chatingkrew
I am currently designing a program (Project work) using visual basic 6, ms access 2000 as a database. my question is that i want to know a code that will enable one to upload a picture (JPEG) via vb6 into the ms access 2000 database. pls note this is not online but on standalone computer.

thank you.
  • +
    0 Votes
    onbliss

    You can store the images in the Access database using an OLE Object field. This does increase the record size and consequently the database size.
    Alternatively, you can store the images on a local drive/path and store the full path in one of the records. You can write VBA code to display (load ) images. This keeps the size of the database in check, but adds the onus to ensure images are backed up and not deleted through the file system.

    +
    0 Votes
    mmveke

    I think onbliss has the perfect solution for you, just make sure you store the pictures in the same folder as your database and make sure they are backed up with your database

    +
    0 Votes
    udara_fdo

    I need to know the sample coding has to be done to upload the picture to that folder and review the pictures to a command and how to delete a particular photo whenever I need

    +
    0 Votes
    kevin.stafferton

    I did a similar thing in Acess VBA
    only storing an Excel workbook in the database.

    First load the image into an ADO stream object.

    Set st = new ADODB.stream
    st.Type = adTypeBinary
    st.Open
    st.LoadFromFile "imagefilename"

    The read the stream into the OLE field value.

    .Fields("Fieldname").Value = st.Read()

    +
    0 Votes
    trimurarisingh

    Dim FileLength As Long
    Dim Numblocks As Integer
    Dim LeftOver As Long
    Const BlockSize = 1000000 'This size can be experimented with for
    Dim ByteData() As Byte 'Byte array for picture file.
    Dim DestFileNum As Integer
    Dim DiskFile As String
    Dim rr As Integer

    ''''''''''''''''''Insert Picture in Table'''''''''''''''''''
    If Trim(CommonDialog1.FileName) = "" Then
    CommonDialog1.FileName = "App.path & "\photo.jpg"
    End If

    Open CommonDialog1.FileName For Binary As #1
    ReDim MyArray(LOF(1))
    Get #1, , MyArray()
    Close #1
    ''''''''''''insert picture in table''''''''

    RSDetails.Fields("emp_photo").AppendChunk MyArray()
    ''Rsdetails is the recordset of table'''
    '''"emp_photo" is field's of table'''
    ''Appendchunk is use for load image in table''


    ''''''''''''''Display Picture In Image OR PictureBox From Table'''''''''''
    DiskFile = "App.path & "\photo.jpg"

    If Len(Dir$(DiskFile)) > 0 Then
    Kill DiskFile
    End If

    DestFileNum = FreeFile
    Open DiskFile For Binary As DestFileNum
    FileLength = TempDetails("emp_photo").ActualSize
    Numblocks = FileLength / BlockSize
    LeftOver = FileLength Mod BlockSize

    ByteData() = TempDetails("emp_photo").GetChunk(LeftOver)
    Put DestFileNum, , ByteData()

    For I = 1 To Numblocks
    ByteData() = TempDetails("emp_photo").GetChunk(BlockSize)
    Put DestFileNum, , ByteData()
    Next I

    Close DestFileNum
    Image1.Picture = LoadPicture("App.path & "\photo.jpg")
    '''''''''''''''end modifiction section'''''''''''''''
    ''''''''''''''

    +
    0 Votes
    nitesh09911

    hello
    ms access is not support to upload a picture in ur data base,becoz ms access is not support that type of data type(data type is blob) u can upload image through mysql

    +
    0 Votes
    kevin.stafferton

    Access has a datatype of OLE Object that can store any kind of binary data you like, just like BLOBs.

    I suggest you read other people's replies before spreading misinformation like this.

    +
    0 Votes
    majumder.goutam

    how store image in ms access database

  • +
    0 Votes
    onbliss

    You can store the images in the Access database using an OLE Object field. This does increase the record size and consequently the database size.
    Alternatively, you can store the images on a local drive/path and store the full path in one of the records. You can write VBA code to display (load ) images. This keeps the size of the database in check, but adds the onus to ensure images are backed up and not deleted through the file system.

    +
    0 Votes
    mmveke

    I think onbliss has the perfect solution for you, just make sure you store the pictures in the same folder as your database and make sure they are backed up with your database

    +
    0 Votes
    udara_fdo

    I need to know the sample coding has to be done to upload the picture to that folder and review the pictures to a command and how to delete a particular photo whenever I need

    +
    0 Votes
    kevin.stafferton

    I did a similar thing in Acess VBA
    only storing an Excel workbook in the database.

    First load the image into an ADO stream object.

    Set st = new ADODB.stream
    st.Type = adTypeBinary
    st.Open
    st.LoadFromFile "imagefilename"

    The read the stream into the OLE field value.

    .Fields("Fieldname").Value = st.Read()

    +
    0 Votes
    trimurarisingh

    Dim FileLength As Long
    Dim Numblocks As Integer
    Dim LeftOver As Long
    Const BlockSize = 1000000 'This size can be experimented with for
    Dim ByteData() As Byte 'Byte array for picture file.
    Dim DestFileNum As Integer
    Dim DiskFile As String
    Dim rr As Integer

    ''''''''''''''''''Insert Picture in Table'''''''''''''''''''
    If Trim(CommonDialog1.FileName) = "" Then
    CommonDialog1.FileName = "App.path & "\photo.jpg"
    End If

    Open CommonDialog1.FileName For Binary As #1
    ReDim MyArray(LOF(1))
    Get #1, , MyArray()
    Close #1
    ''''''''''''insert picture in table''''''''

    RSDetails.Fields("emp_photo").AppendChunk MyArray()
    ''Rsdetails is the recordset of table'''
    '''"emp_photo" is field's of table'''
    ''Appendchunk is use for load image in table''


    ''''''''''''''Display Picture In Image OR PictureBox From Table'''''''''''
    DiskFile = "App.path & "\photo.jpg"

    If Len(Dir$(DiskFile)) > 0 Then
    Kill DiskFile
    End If

    DestFileNum = FreeFile
    Open DiskFile For Binary As DestFileNum
    FileLength = TempDetails("emp_photo").ActualSize
    Numblocks = FileLength / BlockSize
    LeftOver = FileLength Mod BlockSize

    ByteData() = TempDetails("emp_photo").GetChunk(LeftOver)
    Put DestFileNum, , ByteData()

    For I = 1 To Numblocks
    ByteData() = TempDetails("emp_photo").GetChunk(BlockSize)
    Put DestFileNum, , ByteData()
    Next I

    Close DestFileNum
    Image1.Picture = LoadPicture("App.path & "\photo.jpg")
    '''''''''''''''end modifiction section'''''''''''''''
    ''''''''''''''

    +
    0 Votes
    nitesh09911

    hello
    ms access is not support to upload a picture in ur data base,becoz ms access is not support that type of data type(data type is blob) u can upload image through mysql

    +
    0 Votes
    kevin.stafferton

    Access has a datatype of OLE Object that can store any kind of binary data you like, just like BLOBs.

    I suggest you read other people's replies before spreading misinformation like this.

    +
    0 Votes
    majumder.goutam

    how store image in ms access database