retrieving pictures

  • Thread starter Thread starter Brad Allison
  • Start date Start date
B

Brad Allison

Okay, so I got it down on how to store a bit stream (jpeg file) in Access
using Visual Basic .NET. Now when I want to pull that information back to
the form and display the picture I am guessing that it is not as easy as
just binding a picture box to the Picture field in my table as it is not
letting me bind to that field.

What is required to read this file back to the form and display the
information.

Thanks for the help.

Brad
 
Hi Brad,

Mostly this
Dim abyt() as byte = DirectCast(ds.Tables(0).Rows(0)(0), Byte())
Dim ms As New IO.MemoryStream(abyt)
Me.PictureBox1.Image = Image.FromStream(ms)

(the zeros are here the indexes)

I hope this helps,


Cor
 
Cor,

Thanks for the information. I will try this later this afternoon and let
you know.

Brad
 
¤ Okay, so I got it down on how to store a bit stream (jpeg file) in Access
¤ using Visual Basic .NET. Now when I want to pull that information back to
¤ the form and display the picture I am guessing that it is not as easy as
¤ just binding a picture box to the Picture field in my table as it is not
¤ letting me bind to that field.
¤
¤ What is required to read this file back to the form and display the
¤ information.

It depends upon how it was stored. If you stored it as a simple binary stream then it's relatively
easy to retrieve. If it was stored as an OLE Object, using a host application, then it will contain
OLE header information, making it difficult or impossible to retrieve.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Cor,

Your suggestion actually works. For now I only have four records (for
testing) and only one of these records holds a picture. That record when
selected displays the picture in the picture box, but here is the problem
now. When I select one of the other three records without a picture I would
assume that the picture box would be empty, but it still keeps the picture
from before.

Any suggestions?

Thanks.

Brad
 
Brad Allison said:
Your suggestion actually works. For now I only have four records (for
testing) and only one of these records holds a picture. That record when
selected displays the picture in the picture box, but here is the problem
now. When I select one of the other three records without a picture I would
assume that the picture box would be empty, but it still keeps the picture
from before.

Any suggestions?

Well, I'm surprised it doesn't throw an exception or something similar
- I'd use IsNull to check whether or not the value is null before going
through Cor's code, and if it is, set the image to a blank one.
 
Hi Brad,

You did read probably already Jons comment, however I do not know if you use
C# or VB.net, my codesample was VB.net, Jons comment in VB.net is something
as.

If ds.Tables(0).Rows(0)(0) Is DBNull.Value Then
Me.PictureBox1.Image = Nothing
End If

I hope this helps?

Cor
 
Cor,

I did try something like that but I don't think I configured it correctly.
I will try this soon and let you know.

By the way, I am using VB. And no, it did not throw an exception.

Thanks again.,

Brad
 
Cor,

It all works now. Thanks for all of your help - and everyone else. But I
have one other question that I will start a new thread on - called "Working
with Strings."

Brad
 
Back
Top