VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Page 1 of 1
  • You cannot start a new topic
  • Reply Reply

Access database & vb.net picture box Rate Topic: -----

#1 devarsh  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 22-December 08


Dream Kudos: 0

Share |

Access database & vb.net picture box

Posted 24 December 2008 - 04:38 AM

hi i am devarsh..

i have a problem here..

i have a form where a user can upload images into access data base..but when i insert this images into my access data base it works fine..

but now the problem occurs when i want to retrieve the stored images from my database to my picture box in doing so..i noticed that the images are stored in long binary file format in the access data base to as to how to convert this binary image file into jpeg file so that i can display images stored into my data base in to my picturebox...

when i used ctype method it gave me an error saying cannot convert byte() into system.image...so now my question is as to how can we convery this binary file back to its original jpeg format..

Any type of help would be appreciated thanx in advance..
Was This Post Helpful? 0
  • +
  • -


#2 jjsaw5  Icon User is offline

  • I must break you
  • Icon

Reputation: 37
  • View blog
  • Posts: 2,876
  • Joined: 04-January 08


Dream Kudos: 125

Expert In: Mothers

Re: Access database & vb.net picture box

Posted 24 December 2008 - 04:42 AM

Please do not double post your questions. This also applies for posting the same question in another forum.


Thank you!
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • iHater.Init(this);
  • Icon

Reputation: 1364
  • View blog
  • Posts: 19,696
  • Joined: 26-July 07


Dream Kudos: 12925

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

Re: Access database & vb.net picture box

Posted 01 January 2009 - 02:08 PM

This is more of a VB.NET question so it's being moved to VB.NET :)

Also, show us the code you've used to try and accomplish this
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • iHater.Init(this);
  • Icon

Reputation: 1364
  • View blog
  • Posts: 19,696
  • Joined: 26-July 07


Dream Kudos: 12925

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

Re: Access database & vb.net picture box

Posted 01 January 2009 - 02:26 PM

Just for the hell of it, here is how I would retrieve an image from an Access database. First I would create a function that turned the data from a byte format to a Bitmap format using the MemoryStream Class and pass it a byte array containing my image data

Public Function GetImageFromDB(ByRef imageName As String) As Bitmap
    Try
        Dim conn As New OleDb.OleDbConnection
        Dim cmd As OleDb.OleDbCommand
        Dim reader As OleDb.OleDbDataReader

        conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\YourDBFile.mdb;User Id=YourUsername;Password=YourPassword;"
        conn.Open()

        cmd = conn.CreateCommand()
        cmd.CommandText = "SELECT YourColumnName FROM YourTable WHERE ColumnName = '" & imageName & "'"
        reader = cmd.ExecuteReader

        If reader.Read Then
            Dim imgByteArray() As Byte
            Try
                imgByteArray = CType(reader(0), Byte())
                Dim stream As New System.IO.MemoryStream(imgByteArray)
                Dim bmp As New Bitmap(stream)
                stream.Close()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
                Return Nothing                    
            End Try
        End If

        reader.Close()
        conn.Close()

        cmd.Dispose()
        conn.Dispose()
        
        Return bmp            
    Catch ex As Exception
        MessageBox.Show(ex.Message)
        Return Nothing            
    End Try
End Function



Then I would do something like this

PictureBox1.Image = GetImageFromDB(TextBox1.Text)



Hope that helps :)
Was This Post Helpful? 1

Page 1 of 1
  • You cannot start a new topic
  • Reply Reply


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users