Invalid cast exception was unhandled
The error is in "me.picturebox3.image = dt.rows(0).item("pic")
Unable to cast object of type system.byte[]
to type system.drawing.image
.
Dim dt as new datatable
Da.fill(dt)
Me.picturebox3.image = dt.rows(0).item("pic")
I am new in calling images from data table to picturebox. Help please.. Thanks
You need to find a way to construct an object of type System.Drawing.Image
from the System.Byte()
you currently have on hand.
Here's how you do it:
Dim bytes As Byte() = CType(dt.Rows(0).Item("pic"), Byte())
Dim ms As New MemoryStream(bytes)
Me.picturebox3.Image = Image.FromStream(ms)
This will work as long as your Byte()
is in a format that can be handled out of the box, ie JPEG, BMP etc.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.