There's probably a quick solution to this, but I'm struggling with VB2008 Express. Her's my situation anyway:
A simple database has been created in Access, which is just basically a table of text, with some images as entries.
A form has been created in VB2008 Express and linked to the database. Either a combibox, text boxes or pictureboxes are linked to a column form the database. The first row entries are all displayed correctly in the relavant boxes (except for the images, which for some reason aren't displayed). If another value in the comibox is selected, the other box values don't change and there is still no images visible....can anyone help please?


You have to change the data (access database) from a byte format into a bitmap format. You can do that with the MemoryStreamClass.

Public Function GetImageFromDB(ByRef imageName As String) As Bitmap 
        Dim conn As New OleDb.OleDbConnection 
        Dim cmd As OleDb.OleDbCommand 
        Dim reader As OleDb.OleDbDataReader 
        conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\YourDBFile.mdb;" 
        cmd = conn.CreateCommand() 
        cmd.CommandText = "SELECT YourColumnName FROM YourTable WHERE ColumnName = '" & imageName & "'" 
        reader = cmd.ExecuteReader 
        If reader.Read Then 
            Dim imgByteArray() As Byte 
                imgByteArray = CType(reader(0), Byte()) 
                Dim stream As New System.IO.MemoryStream(imgByteArray) 
                Dim bmp As New Bitmap(stream) 
            Catch ex As Exception 
                Return Nothing                     
            End Try 
        End If 
        Return bmp             
    Catch ex As Exception 
        Return Nothing             
    End Try 
End Function

Then you need to do something like this:

PictureBox1.Image = GetImageFromDB(TextBox1.Text)

Edited 6 Years Ago by Luc001: n/a

This article has been dead for over six months. Start a new discussion instead.