We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,111 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Retrieving Image From Database (MS Access)

Hi, I just wanna ask what's the problem with my code in retrieving image from database into a picturebox.

Private Sub ShowDetails()
        Try
            Dim cn As New OleDb.OleDbConnection
            Dim cmd As OleDb.OleDbCommand
            Dim dr As OleDb.OleDbDataReader

            cn.ConnectionString = mstrConnection
            cn.Open()

            cmd = cn.CreateCommand()
            cmd.CommandText = "SELECT myimage FROM employees WHERE ID = '" & DataGridView.CurrentRow.Cells(0).Value & "'"

            dr = cmd.ExecuteReader

            If dr.Read Then
                Dim bytImage() As Byte

                Try
                    bytImage = CType(dr(0), Byte())
                    Dim ms As New System.IO.MemoryStream(bytImage)
                    Dim bmImage As New Bitmap(ms)
                    ms.Close()

                    myimage.Image = bmImage
                    myimage.Refresh()
                Catch ex As Exception
                    MsgBox(ex.ToString)
                End Try
            End If

            dr.Close()
            cn.Close()

            cmd.Dispose()
            cn.Dispose()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
1
Contributor
1
Reply
51 Minutes
Discussion Span
3 Months Ago
Last Updated
3
Views
Question
Answered
yvrej17
Junior Poster in Training
50 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Ooopss. I Already solved :) sorry.

yvrej17
Junior Poster in Training
50 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Self-Answered as of 3 Months Ago

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0961 seconds using 2.79MB