我正在做一个项目,我有一个通过 datagridview 显示的图像列表。当在 datagridview 中单击特定图像时,我想将图像加载到图片框中。
我的代码
Private Sub DataGridView1_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
sql.Open()
cmd = New SqlCommand("select pic from detail4 where id='" & DataGridView1.CurrentRow.Cells(0).Value() & "'", sql)
Dim imageData As Byte() = DirectCast(cmd.ExecuteScalar(), Byte())
If Not imageData Is Nothing Then
Using ms As New MemoryStream(imageData, 0, imageData.Length)
ms.Write(imageData, 0, imageData.Length)
PictureBox1.BackgroundImage = Image.FromStream(ms, True)
End Using
End If
End Sub
我得到内存不足异常..可能是什么问题。请帮忙