none
Which Datatype I have to use for Images in MS-Access Database. RRS feed

  • Question

  • Hi Friends...

    I am Atif. I have stucked in a query. Please suggest me. 

    • Which Datatype I have to use for Images in MS-Access Database ?

    Thanks in advance..

    Regards

    Atif

    • Moved by Bob Beauchemin Thursday, April 16, 2015 4:06 PM Moved to a more appropriate forum for best results
    Thursday, April 16, 2015 12:17 PM

Answers

  • byte array. 

    But there's an undocumented variable length OLE header created by Access if you use it to insert data, so unless you know what is in there, the column is pretty much useless. 



    Visual C++ MVP

    Thursday, April 16, 2015 8:15 PM
  • Depends upon whether you are referring to a variable or the data type of the column in which to store the data. For a table you should use an OLE Object. For example, you could use something like the following to store an image into a Access table from a PictureBox (sans OLE header):

            Dim AccessConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
               "Data Source=C:\Test Files\db1 XP.mdb")
            Dim AccessCommand As New OleDbCommand("INSERT INTO BlobTable (ID, BLOB) " & _
                "VALUES (@ID, @BLOBData)", AccessConnection)
            Dim PictureMemoryStream As MemoryStream = New MemoryStream()
            Form3.PictureBox1.Image.Save(PictureMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg)
            Dim BLOBData(PictureMemoryStream.Length - 1) As Byte
            PictureMemoryStream.Position = 0
            PictureMemoryStream.Read(BLOBData, 0, PictureMemoryStream.Length)
            AccessCommand.Parameters.AddWithValue("ID", 7)
            AccessCommand.Parameters.Add("BLOBData", OleDbType.LongVarBinary, BLOBData.Length, DataRowVersion.Current).Value = BLOBData
            AccessConnection.Open()
            AccessCommand.ExecuteNonQuery()
            AccessConnection.Close()
    


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, April 17, 2015 1:05 PM

All replies

  • byte array. 

    But there's an undocumented variable length OLE header created by Access if you use it to insert data, so unless you know what is in there, the column is pretty much useless. 



    Visual C++ MVP

    Thursday, April 16, 2015 8:15 PM
  • Thanks Dear..
    Friday, April 17, 2015 5:35 AM
  • Depends upon whether you are referring to a variable or the data type of the column in which to store the data. For a table you should use an OLE Object. For example, you could use something like the following to store an image into a Access table from a PictureBox (sans OLE header):

            Dim AccessConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
               "Data Source=C:\Test Files\db1 XP.mdb")
            Dim AccessCommand As New OleDbCommand("INSERT INTO BlobTable (ID, BLOB) " & _
                "VALUES (@ID, @BLOBData)", AccessConnection)
            Dim PictureMemoryStream As MemoryStream = New MemoryStream()
            Form3.PictureBox1.Image.Save(PictureMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg)
            Dim BLOBData(PictureMemoryStream.Length - 1) As Byte
            PictureMemoryStream.Position = 0
            PictureMemoryStream.Read(BLOBData, 0, PictureMemoryStream.Length)
            AccessCommand.Parameters.AddWithValue("ID", 7)
            AccessCommand.Parameters.Add("BLOBData", OleDbType.LongVarBinary, BLOBData.Length, DataRowVersion.Current).Value = BLOBData
            AccessConnection.Open()
            AccessCommand.ExecuteNonQuery()
            AccessConnection.Close()
    


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, April 17, 2015 1:05 PM