我正在尝试在我的 DataGridView 中的 PictureBox 中显示图像.
我使用 SQL Server 作为数据库.
I'm trying to show an image in my DataGridView in a PictureBox.
I'm using SQL Server as database.
Me.PictureBox2.Image = DataGridView2.Item(10, i).Value
我想知道我使用的是什么代码.
I'm wondering what code I am using.
这是错误说:
Unable to cast object of type 'System.Byte[]' to type 'System.Drawing.Image'.
您需要将 Blob 字段 Byte 数组(现在是 DataGridView 单元格值)转换为 Image对象.
You need to convert the Blob field Byte array (now a DataGridView cell Value) to an Image object.
一个 MemoryStream 可用于收集Byte 数组并成为 Stream 源"nofollow noreferrer">Image.FromStream() 方法.
A MemoryStream can be used to collect the Byte array and become the Stream source for the Image.FromStream() method.
If DataGridView2(10, 1).Value Is Nothing Then Return
Using ms As MemoryStream = New MemoryStream(CType(DataGridView2(10, i).Value, Byte()))
PictureBox2.Image?.Dispose()
PictureBox2.Image = Image.FromStream(ms)
End Using
这篇关于如何将 DataGridView 中的图像显示到 PictureBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
我可以在不编写 SQL 查询的情况下找出数据库列表Can I figure out a list of databases and the space used by SQL Server instances without writing SQL queries?(我可以在不编写 SQL 查询的情况下
如何创建对 SQL Server 实例的登录?How to create a login to a SQL Server instance?(如何创建对 SQL Server 实例的登录?)
如何通过注册表搜索知道SQL Server的版本和版本How to know the version and edition of SQL Server through registry search(如何通过注册表搜索知道SQL Server的版本和版本)
为什么会出现“数据类型转换错误"?使用 ExWhy do I get a quot;data type conversion errorquot; with ExecuteNonQuery()?(为什么会出现“数据类型转换错误?使用 ExecuteNonQuery()?)
WinForms 应用程序设计——将文档从 SQL Server 移动WinForms application design - moving documents from SQL Server to file storage(WinForms 应用程序设计——将文档从 SQL Server 移动到文件存
适用于 Windows XP 的 SQL Server 2012 Management StudioSQL Server 2012 Management Studio for Windows XP(适用于 Windows XP 的 SQL Server 2012 Management Studio)