Load Bitmap ole object from access to VB.net form

NJKJHVB

New member
Joined
Jun 10, 2004
Messages
1
Programming Experience
3-5
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 :)
 

haydez

Member
Joined
Jun 15, 2004
Messages
6
Programming Experience
1-3
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
 

Attachments

Madhivanan

New member
Joined
Jun 24, 2004
Messages
4
Programming Experience
3-5
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
Madhivanan
 
Last edited:

haydez

Member
Joined
Jun 15, 2004
Messages
6
Programming Experience
1-3
Showing Pic from OLE Object

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


VB.NET:
 	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
			File.Delete(txtOpen.Text)
		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 
		sConn.Open()
		Dim myReader As OleDbDataReader
		Try
			myReader = LogoCmd.ExecuteReader()
		Catch ee As System.Data.OleDb.OleDbException
			MessageBox.Show(ee.Message)
		End Try
		myReader.Read()
		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)
		bw.Flush()
		bw.Close()
		fs.Close()
	   myReader.Close()
		sConn.Close()
		If chkPic.Checked = True Then
			LoadPicture(txtOpen.Text)
		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
 

haydez

Member
Joined
Jun 15, 2004
Messages
6
Programming Experience
1-3
Modified File

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

Attachments

Madhivanan

New member
Joined
Jun 24, 2004
Messages
4
Programming Experience
3-5
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?
Madhivanan
 

haydez

Member
Joined
Jun 15, 2004
Messages
6
Programming Experience
1-3
Picture

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??
 

Madhivanan

New member
Joined
Jun 24, 2004
Messages
4
Programming Experience
3-5
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.

Madhivanan
 

Attachments

Top Bottom