user3221790
user3221790

Reputation: 33

My Picture box is not giving the output of an image

Help my code is not running but its catching my error message, I want to show the images from my database and i will pass it to my picture box

'This is my code

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch.Click
        Try
            disconnect()
            connect()
            cmd = New Odbc.OdbcCommand("Select * FROM tblemployee WHERE lname ='" & Trim(TextBox1.Text.TrimEnd()) & "'", con)
            dr = cmd.ExecuteReader

            If dr.Read() Then

                PictureBox1.Image = (dr("emp_pix"))
            Else
                MessageBox.Show("No Information Record, Please Name!")
            End If
        Catch ex As Exception
            Debug.WriteLine("Please try again" & ex.Message)

        End Try
End Sub

Upvotes: 1

Views: 81

Answers (1)

Vignesh Kumar A
Vignesh Kumar A

Reputation: 28413

You can't display directly byte as Image. you need to convert it and display it.

Try like this

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch.Click
        Try
            disconnect()
            connect()
            cmd = New Odbc.OdbcCommand("Select * FROM tblemployee WHERE lname ='" & Trim(TextBox1.Text.TrimEnd()) & "'", con)
            dr = cmd.ExecuteReader

            If dr.Read() Then
                Dim bytBLOBData() As Byte = dr("emp_pix")
                Dim stmBLOBData As New MemoryStream(bytBLOBData)
                PictureBox1.Image = Image.FromStream(stmBLOBData)
            Else
                MessageBox.Show("No Information Record, Please Name!")
            End If
        Catch ex As Exception
            Debug.WriteLine("Please try again" & ex.Message)

        End Try
End Sub

Upvotes: 1

Related Questions