Trying to get Image from Access OLE Object into PictureBox in VB code
I am programming with Access 2007
VB.net in Visual Studio 2010
I am trying to have my VB program read the database, extract the .bmp image, and assign it to a PictureBox on the fly (I am actually creating a Group on the fly and filling it with data from the database that are selected by my query. One of the fields is "image". All of my other fields are successfully transferring from the DB to the group box.) My problem is converting the OLE Object to a picture/image that I can assign to the PictureBox.
I am using TableAdapters and queries set up in an .xsd.
I have a database with an OLE Object field.
Here is a code snipit of my database set up:
Dim ta AsNew dsWhiteboardTableAdapters.MonstersTableAdapter
Dim monsterList AsNewdsWhiteboard.MonstersDataTable
Dim monster AsdsWhiteboard.MonstersRow
Dim newMonster AsGroupBox
ta.Fill(monsterList)
Dim cnt AsInteger = monsterList.Rows.Count
If cnt > 0 Then
For r AsInteger = 0 To cnt - 1
monster = CType(monsterList.Rows(r), dsWhiteboard.MonstersRow)
newMonster = NewGroupBox
'Add Image to group for Pic
newPic = NewPictureBox
newPic.Location = NewPoint(72, 5)
newPic.Size = NewSize(54, 54)
Participants.Add(newMonster)
grpCounter += 1
Next
I have tried several ways of getting the image into my picturebox, all lead to errors. I also searched forums for solutions and none seemed to work in my scenario.
If you need additional code, i would be glad to provide.
Any suggestions?
Re: Trying to get Image from Access OLE Object into PictureBox in VB code
Here is his code example:
Dim connection As New SqlConnection("connection string here")
Dim command As New SqlCommand("SELECT Picture FROM MyTable WHERE ID = 1", connection)
connection.Open()
Dim pictureData As Byte() = DirectCast(command.ExecuteScalar(), Byte())
connection.Close()
I tried, but where i get confused is with "command". please look at my code sample with TableAdapters. How do I convert my tableAdapter usage to this code sample?