Load Bitmap ole object from access to VB.net form


New member
Jun 10, 2004
Programming Experience
Having an issue figuring out how VB.net can look to an access database which contains bitmap images. :confused: All other text fields load fine from each record in the database, based on setting their text attribute under the databindings section of properties to the appropriate fields in the dataset. The problem is we cannot figure out how to bind the bitmap images (Stored in access as ole objects) to a picturebox control on our form. Any ideas would be GREATLY appreciated. This has me stumped as well as others I have asked.

Thank you all very much for taking the time to answer our question.

Have a great day :)
I worked on this for a while here ya go

The trick to get this to work is to use an OLE Object But you have to enter in the Binary Array and then pull it out via VB.NET here's a Sample App


  • TestDBOle.zip
    38.5 KB · Views: 595
Hai haydez,
I went thru your download. But after running the application, a new record is added in the table with dNo, dName and dPic. But what I am trying to do is I want to display the picture stored as a OLE object in MS Access in VB or VB.Net picture or image control. Is there a way to do this? How can I modify your program to achieve this?

Expecting your reply
Last edited:
Showing Pic from OLE Object

Add a Check Box and Add a Picture Box here's the Code

 	Private Sub ReadFileFromDataBase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butRead.Click
		If txtOpen.Text = "" Or txtOpen.Text = Nothing Then Exit Sub
		If File.Exists(txtOpen.Text) = True Then
		End If
 Dim str_SQL as String = "SELECT Data.dID, Data.dName, Data.dPic FROM Data ORDER BY Data.dID DESC"
 Dim LogoCmd As New OleDbCommand(str_SQL, sConn)
		Dim fs As FileStream 'Writes   the Blob to a file(*.bmp) 
		Dim bw As BinaryWriter 'Streams the Binary data to the File Object 
		Dim bufferSize As Integer = 100 'The  Size of the BLOB Buffer 
		Dim OutByte() As Byte
 Dim retval As Long 'The  Bytes returned from GetBytes 
		Dim startIndex As Long 'TheStarting Position from the BLOB output 
		Dim myReader As OleDbDataReader
			myReader = LogoCmd.ExecuteReader()
		Catch ee As System.Data.OleDb.OleDbException
		End Try
		lblDBFileName.Text = "File Name:" & myReader.GetValue(1)
		fs = New FileStream(txtOpen.Text, FileMode.OpenOrCreate, FileAccess.Write)

		bw = New BinaryWriter(fs)
	   startIndex = 0
	  OutByte = myReader(2) 
	   bw.Write(OutByte, 0, OutByte.Length)
		If chkPic.Checked = True Then
		End If
	End Sub

	Private Sub LoadPicture(ByVal FileLocation As String)
		Dim BM As Bitmap
		BM = New Bitmap(BM.FromFile(FileLocation))
		PictureBox1.Image = BM
	End Sub
Modified File

Here's the Modified fileForgot to upload last time
Sorry once again I have been to lazy to clean it


  • Form1.zip
    3 KB · Views: 281
Hai heydez,
I included the modified form. But when running I am getting the following error.

"An unhandled exception of type 'System.OutOfMemoryException' occurred in system.drawing.dll
Additional information: Out of memory."

The above error occurs at
BM = New Bitmap(BM.FromFile(FileLocation))
procedure name LoadPicture.

what is the solution?

What is the Size of the picture??

And did you save a picture to the database?

What are you trying to load in to the picture box?

The Orginal DB I sent I don't think has any pics so did you, load one or did you save one to it??
The size of the picture is 2kb. I added it to db thru VB6. I am trying to load the bmp file. I have attached your program and the database has records.



  • TestDBOle.zip
    35.7 KB · Views: 264