繁体   English   中英

无法转换vb.net类型的对象

[英]Unable to cast object of type vb.net

无效的强制转换异常未处理

错误出现在“ me.picturebox3.image = dt.rows(0).item(“ pic”)

无法将类型为system.byte[]对象转换为类型为system.drawing.image

Dim dt as new datatable
Da.fill(dt)
Me.picturebox3.image = dt.rows(0).item("pic")                  

我是从数据表到图片框调用图像的新手。 请帮助..谢谢

您需要找到一种从当前手头的System.Byte()构造类型为System.Drawing.Image的对象的方法。

这是您的操作方式:

Dim bytes As Byte() = CType(dt.Rows(0).Item("pic"), Byte())
Dim ms As New MemoryStream(bytes)

Me.picturebox3.Image = Image.FromStream(ms)

只要您的Byte()可以使用开箱即用的格式(例如JPEG,BMP等),它就可以工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM