can anyone tell me how to save .jpg images in access database????

Dani AI

Generated

— short, practical answer and a couple of cautions. was right to point you at examples, but here is a concrete, safe approach for VB.NET + Access and what to watch out for.

Saving: for .accdb use the Attachment field (introduced in Access 2007) when you need Access forms/reports to display images or want built‑in compression; it stores native files and avoids OLE wrapper problems. If you must store raw bytes in a table column use a binary column (OLE Object in .mdb, a binary/blob column in the backend) and write the JPEG bytes with a parameterized query. (support.microsoft.com)

VB.NET pattern (insert and later retrieve):

' read file to byte array
Dim bytes() As Byte = System.IO.File.ReadAllBytes("C:\photos\pic.jpg")

' connection string: Jet for .mdb, ACE for .accdb
Dim connStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\db\MyDB.accdb;"

Using cn As New OleDb.OleDbConnection(connStr)
  cn.Open()
  Using cmd As New OleDb.OleDbCommand("INSERT INTO Photos (ImageData) VALUES (?)", cn)
    Dim p As New OleDb.OleDbParameter("@img", OleDb.OleDbType.LongVarBinary, bytes.Length)
    p.Value = bytes
    cmd.Parameters.Add(p)
    cmd.ExecuteNonQuery()
  End Using
End Using

Use OleDbParameter (choose LongVarBinary for larger images), set Size to the byte length, and always use parameters (no concatenation). (learn.microsoft.com)

Retrieval: pull the byte[] with a DataReader, then convert with a MemoryStream and Image.FromStream (or write bytes back to disk). Note: when you insert raw JPEG bytes you’ll often see “Long binary data” in Access tables — Access forms/reports typically won’t render that unless the data is in an Attachment field or stored with the OLE wrapper Access expects. If you need images to show inside Access UI, prefer Attachment or import/paste via Access itself. (stackoverflow.com)

Practical cautions: Access has a small maximum file size (2 GB overall) and will bloat quickly if you store many images. For anything beyond a handful of pictures prefer storing files on disk (or a blob store/CDN) and keep only paths/IDs in the DB — better performance, simpler backups and scaling. (stackoverflow.com)

Troubleshooting tips: test with a known JPEG, verify the parameter Size, confirm provider (Jet vs ACE) is installed, and try retrieving the bytes and saving to disk first to ensure you wrote the data correctly before wiring up forms/reports.

Recommended Answers

All 3 Replies

does not anyone know about it????

thanks.................

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.