-1
我正在一個項目中,我有一個通過datagridview顯示的圖像列表。 我想在datagridview中點擊特定圖像時將圖像加載到圖像框。如何從datagridview加載圖像在鼠標單擊到vb.net中的圖片框
我的代碼
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
我走出內存異常.. 什麼可能是問題。 請幫助
是什麼'pic'列數據類型? – Sathish 2013-04-22 06:00:33
可能重複的[如何將圖像從SQL Server加載到圖片框?](http://stackoverflow.com/questions/8084590/how-to-load-image-from-sql-server-into-picture-box) – Neolisk 2013-04-23 21:35:53