How can I fix the error: Parameter is not valid

1

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
    
asked by Joel Lpz 117 19.07.2017 в 23:32
source

1 answer

1

If you are going to add a background image in the PictureBox, the line is not necessary: PictureBox1.BackgroundImage = Nothing , delete the line that I commented:

  'PictureBox1.BackgroundImage = Nothing //Elimina esta linea!
  PictureBox1.BackgroundImage = (Image.FromStream(mStream))
    
answered by 19.07.2017 в 23:42