I have an error that does not let me show the image saved in the database but I can not find how to fix it.
It says that the error starts from:
PictureBox1.BackgroundImage = (Image.FromStream(mStream))
My code is:
Private Sub Mostrar_Click(sender As Object, e As EventArgs) Handles Mostrar.Click
Dim dt As New DataTable
Dim mStream As New IO.MemoryStream()
Try
cadena.Close()
cadena.Open()
comando = "Select * from ImagenesPlayStation where codigo = '" & TextBox2.Text & "'"
con = New SqlDataAdapter(comando, cadena)
con.Fill(dt)
If dt.Rows.Count > 0 Then
TextBox1.Text = dt.Rows(0).Item("nombre")
Dim imageBuffer() As Byte = CType(dt.Rows(0).Item("Imagen"), Byte())
mStream = New IO.MemoryStream(imageBuffer)
PictureBox1.BackgroundImage = Nothing
PictureBox1.BackgroundImage = (Image.FromStream(mStream))
PictureBox1.BackgroundImageLayout = ImageLayout.Stretch
End If
cadena.Close()
dt.Clear()
dt.Reset()
mStream.Dispose()
mStream.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub