J
Jan Nielsen
Hi
I would like to databind a Picturebox to a SQL Server.
I have a typed Dataset "DSBoernekirken1"
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
OleDbDataAdapter1.Fill(DataSet11)
'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.Image = Image.FromStream(ms)
End Sub
I changed this to
Dim arrPicture() As Byte = CType(DsBoerneKirken1.tPersoner.PhotoColumn,
Byte()) ' Intellisense only allows Photocolumn, not Photo. Then I receive
the error "Value of type System.data.Datacolumn can not be converted to
1-dimensional array of Byte"
' I have also tried
'Dim arrPicture2() As Byte =
CType(DsBoerneKirken1.tPersonerDataTable.PhotoColumn, Byte())
'Dim arrPicture3() As Byte = CType(DsBoerneKirken1.tPersonerDataTable.Photo,
Byte())
' Dim arrPicture4() As Byte = CType(DsBoerneKirken1.tPersoner.Photo, Byte())
Dim ms As New IO.MemoryStream(arrPicture)
'show the picture in the picturebox
PictureboxPhoto.Image = Image.FromStream(ms)
Can anyone tell me what I am doing wrong?
*****'
I also found
Dim bytBLOBData() As Byte = ds.Tables("BLOBTest").Rows(c -
1)("BLOBData")
Dim stmBLOBData As New MemoryStream(bytBLOBData)
picBLOB.Image = Image.FromStream(stmBLOBData)
Which I changed to
Dim bytBLOBData() As Byte = DsBoerneKirken1.tPersoner.PhotoColumn
Dim stmBLOBData As New MemoryStream(bytBLOBData)
PictureboxPhoto.Image = Image.FromStream(stmBLOBData)
With about the same error.
Best regards
Jan
I would like to databind a Picturebox to a SQL Server.
I have a typed Dataset "DSBoernekirken1"
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
OleDbDataAdapter1.Fill(DataSet11)
'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.Image = Image.FromStream(ms)
End Sub
I changed this to
Dim arrPicture() As Byte = CType(DsBoerneKirken1.tPersoner.PhotoColumn,
Byte()) ' Intellisense only allows Photocolumn, not Photo. Then I receive
the error "Value of type System.data.Datacolumn can not be converted to
1-dimensional array of Byte"
' I have also tried
'Dim arrPicture2() As Byte =
CType(DsBoerneKirken1.tPersonerDataTable.PhotoColumn, Byte())
'Dim arrPicture3() As Byte = CType(DsBoerneKirken1.tPersonerDataTable.Photo,
Byte())
' Dim arrPicture4() As Byte = CType(DsBoerneKirken1.tPersoner.Photo, Byte())
Dim ms As New IO.MemoryStream(arrPicture)
'show the picture in the picturebox
PictureboxPhoto.Image = Image.FromStream(ms)
Can anyone tell me what I am doing wrong?
*****'
I also found
Dim bytBLOBData() As Byte = ds.Tables("BLOBTest").Rows(c -
1)("BLOBData")
Dim stmBLOBData As New MemoryStream(bytBLOBData)
picBLOB.Image = Image.FromStream(stmBLOBData)
Which I changed to
Dim bytBLOBData() As Byte = DsBoerneKirken1.tPersoner.PhotoColumn
Dim stmBLOBData As New MemoryStream(bytBLOBData)
PictureboxPhoto.Image = Image.FromStream(stmBLOBData)
With about the same error.
Best regards
Jan