Hello...

Can anybody help me with this?

1. i have the images of our specimen card, located in my hard disk.
2. i want the image of the speciment card to be display in a picturebox when i type in the name.
3. i already made this in Ms Access using load image via current form. can u help me do it in Visual basic 2008 express.

Thank you very much in advance.

Rene G.

Dani AI

Generated

This adds a short, practical VB.NET 2008 recipe to take the next step after 's question and 's suggestion about using data access. Two common approaches follow: 1) store only the image file path in Access and load the file at runtime (simpler, recommended), 2) store image bytes in the database and load from a byte array (works, but watch for Access OLE wrappers).

Example: database holds a file path (recommended)

Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\data\specimens.mdb;"
Using conn As New System.Data.OleDb.OleDbConnection(connString)
  conn.Open()
  Using cmd As New System.Data.OleDb.OleDbCommand("SELECT ImagePath FROM Specimens WHERE SpecimenName = ?", conn)
    cmd.Parameters.AddWithValue("?", txtName.Text.Trim())
    Dim result = cmd.ExecuteScalar()
    If result IsNot Nothing AndAlso Not Convert.IsDBNull(result) Then
      Dim imgPath = result.ToString()
      If System.IO.File.Exists(imgPath) Then
        Dim bytes = System.IO.File.ReadAllBytes(imgPath)
        Using ms As New System.IO.MemoryStream(bytes)
          Dim img = System.Drawing.Image.FromStream(ms)
          If PictureBox1.Image IsNot Nothing Then PictureBox1.Image.Dispose()
          PictureBox1.Image = New System.Drawing.Bitmap(img)
          PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
        End Using
      End If
    End If
  End Using
End Using

Example: binary image stored in a blob column

Using cmd As New System.Data.OleDb.OleDbCommand("SELECT ImageData FROM Specimens WHERE SpecimenName = ?", conn)
  cmd.Parameters.AddWithValue("?", txtName.Text.Trim())
  Using reader = cmd.ExecuteReader()
    If reader.Read() AndAlso Not reader.IsDBNull(0) Then
      Dim imgBytes = DirectCast(reader(0), Byte())
      Using ms As New System.IO.MemoryStream(imgBytes)
        Dim img = System.Drawing.Image.FromStream(ms)
        If PictureBox1.Image IsNot Nothing Then PictureBox1.Image.Dispose()
        PictureBox1.Image = New System.Drawing.Bitmap(img)
        PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
      End Using
    End If
  End Using
End Using

Notes and troubleshooting

  • If Access stores images as OLE objects (inserted via Access UI) the raw bytes often include an OLE header; the blob approach may fail unless you strip the header. Storing plain file paths or raw image bytes avoids that.
  • Use the ACE provider for .accdb files ("Provider=Microsoft.ACE.OLEDB.12.0") and build your app as x86 when using Jet/ACE 32-bit drivers.
  • Dispose the previous PictureBox.Image before assigning a new one to avoid GDI+ file locks and memory leaks.
  • For long queries, do DB work on a background thread (BackgroundWorker) so the UI stays responsive.

Recommended Answers

All 3 Replies

>can u help me do it in Visual basic 2008 express.

Well. You have to use OleDB data-provider (ADO.NET) class to connect with MS-Access database to retrieve the result.

Thank you very much for your quick response.

How?
Can i do it in Visual basic 2008 with connecting to ms-access?

rene g

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.