getting image from access to picture box

chiba_11

Member
Joined
Oct 8, 2008
Messages
5
Programming Experience
Beginner
hi everyone!

i'm having a problem to get the image that i saved from my dbase to display it in my picturebox. van someone please help me with this problem. thank you very much in advance.:D
 
I'm assuming you have the file in a BLOB column rather than just a path that points to a file.

Don't have an Access db laying around to test with but this should be close.

VB.NET:
		Dim cn As New OleDbConnection("Your connection string")
		Dim cmd As New OleDbCommand("SELECT ImageColumn From YourTable WHERE ImageName = @ImageName", cn)

		cmd.Parameters.AddWithValue("@ImageName", ImageName)
		cn.Open()

		Dim dr As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
		If dr.Read() Then
			Dim b() As Byte = dr.Item("ImageBlobColumn")
			Dim ms As New IO.MemoryStream
			ms.Write(b, 0, b.Length)
			PictureBox1.Image = Image.FromStream(ms)
			ms.Close()
		End If
		dr.Close()

If you've already got the data in a dataset you can do something like this to show the information in a picturebox.

VB.NET:
Dim b() As Byte = CType(ds.Tables("TableName").Rows(1)("ColumnName"), Byte())
 

Latest posts

Back
Top