Hi
I would like to databind a Picturebox to a SQL Server.
I have a typed Dataset "DSBoernekirken 1"
It has a table named "tpersoner" with a column "Photo"
I of course would like to bind the image directly to tpersoner.photo using
Properties (like I do with text fields), but this does not seem to be
possible.
Then I searched some news groups and Knowledgebase and found the following
code:
Sub ShowPicture()
'get the data from the database and put it in the dataset
OleDbDataAdapte r1.Fill(DataSet 11)
'get the byte array and convert it to a picture
Dim arrPicture() As Byte = CType(DataSet11 .Photos.picture , Byte())
Dim ms As New IO.MemoryStream (arrPicture)
'show the picture in the picturebox
PictureBox1.Ima ge = Image.FromStrea m(ms)
End Sub
I changed this to
Dim arrPicture() As Byte = CType(DsBoerneK irken1.tPersone r.PhotoColumn,
Byte()) ' Intellisense only allows Photocolumn, not Photo. Then I receive
the error "Value of type System.data.Dat acolumn can not be converted to
1-dimensional array of Byte"
' I have also tried
'Dim arrPicture2() As Byte =
CType(DsBoerneK irken1.tPersone rDataTable.Phot oColumn, Byte())
'Dim arrPicture3() As Byte = CType(DsBoerneK irken1.tPersone rDataTable.Phot o,
Byte())
' Dim arrPicture4() As Byte = CType(DsBoerneK irken1.tPersone r.Photo, Byte())
Dim ms As New IO.MemoryStream (arrPicture)
'show the picture in the picturebox
PictureboxPhoto .Image = Image.FromStrea m(ms)
Can anyone tell me what I am doing wrong?
*****'
I also found
Dim bytBLOBData() As Byte = ds.Tables("BLOB Test").Rows(c -
1)("BLOBData")
Dim stmBLOBData As New MemoryStream(by tBLOBData)
picBLOB.Image = Image.FromStrea m(stmBLOBData)
Which I changed to
Dim bytBLOBData() As Byte = DsBoerneKirken1 .tPersoner.Phot oColumn
Dim stmBLOBData As New MemoryStream(by tBLOBData)
PictureboxPhoto .Image = Image.FromStrea m(stmBLOBData)
With about the same error.
Best regards
Jan