ข้อมูลรูปภาพถูกบันทึกไว้ใน db เรียบร้อยแล้ว แต่ต้องการให้แสดงเวลาเราคลิกเลือกข้อมูลแต่ละรายการ
ปัญหาคือ ข้อมูลที่เป็นตัวอักษรแสดงทุกอย่าง แต่รูปภาพไม่แสดง ผมต้องการให้มันแสดงเวลาคลิกเลือกแต่ละรายการ
ผู้รู้ช่วยทีครับ
ตัวที่ผมคอมเม้นไว้ผมลองตัวแล้วแต่ยังไม่ได้
Code (VB.NET)
Private Sub DataGridViewWeddingDress_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridViewWeddingDress.CellMouseUp
If e.RowIndex = -1 Then
Exit Sub
End If
With DataGridViewWeddingDress
TextBoxWeddingDressID.Text = .Rows(e.RowIndex).Cells(0).Value.ToString()
TextBoxWeddingDressName.Text = .Rows(e.RowIndex).Cells(1).Value.ToString()
TextBoxWeddingDressQty.Text = .Rows(e.RowIndex).Cells(2).Value.ToString()
TextBoxWeddingDressPrice.Text = .Rows(e.RowIndex).Cells(3).Value.ToString()
TextBoxWeddingDressDay.Text = .Rows(e.RowIndex).Cells(4).Value.ToString()
PictureBox1.Image = ""
' Dim cn As New SqlConnection(ConStr)
' Dim cmd As New SqlCommand("SELECT WeddingID, " & _
'"Picture FROM TableWedding ORDER BY WeddingID", cn)
' Dim da As New SqlDataAdapter(cmd)
'Dim ds As New DataSet()
'da.Fill(ds, "TableWedding")
' Dim c As Integer = ds.Tables("TableWedding").Rows.Count
'If c > 0 Then
'Dim bytBLOBData() As Byte = _
' ds.Tables("TableWedding").Rows(c - 3)("Picture")
' Dim stmBLOBData As New MemoryStream(bytBLOBData)
' PictureBox1.Image = Image.FromStream(stmBLOBData)
' End If
' PictureBox1.Image = ByteToImage(Of Byte)()
' Dim cn As New SqlConnection(ConStr)
' Dim cmd As New SqlCommand("SELECT WeddingID, " & _
'"Picture FROM TableWedding ORDER BY WeddingID", cn)
' Dim dr As SqlDataReader
' cn.Open()
' dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
' If dr.Read Then
'Dim bytBLOBData(dr.GetBytes(1, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte
' dr.GetBytes(1, 0, bytBLOBData, 0, bytBLOBData.Length)
' Dim stmBLOBData As New MemoryStream(bytBLOBData)
' PictureBox1.Image = Image.FromStream(stmBLOBData)
' End If
' dr.Close()
End With
End Sub
Dim conn As New SqlConnection(strConn)
conn.Open()
'Retrieve BLOB from database into DataSet.
Dim sqlCmd As New SqlCommand("SELECT BLOBID, BLOBData FROM tblBLOB ORDER BY BLOBID", conn)
Dim sqlDA As New SqlDataAdapter(sqlCmd)
Dim ds As New DataSet()
sqlDA.Fill(ds, "tblBLOB")
Dim c As Integer = ds.Tables("tblBLOB").Rows.Count
If c > 0 Then
'BLOB is read into Byte array, then used to construct MemoryStream,
'then passed to PictureBox.
Dim byteBLOBData As [Byte]() = New [Byte](-1) {}
byteBLOBData = DirectCast(ds.Tables("tblBLOB").Rows(c - 1)("BLOBData"), [Byte]())
Dim stmBLOBData As New MemoryStream(byteBLOBData)
pbBLOB.Image = Image.FromStream(stmBLOBData)
lblMsg.Text = "File read from the database successfully."
End If
conn.Close()