CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2002
    Posts
    2

    Question database images..... sigh

    pretty new with programming, and having one whopper of a time with this one.. I have a populated database, i have created a dataset ( i suspect this wasnt the best way) and i have bound feilds to textboxes, what i want to do is bind a long binary data feild in the access database to a picturebox, i seen examples of this in vb4,5,and 6 but not .net, anyone have a clue? Should i also not be useing a dataset, and instead be declareing the felds as varibles? if so, how would i browse the records?

    any help, even guesses as this point would be appreciated, ive been stuck on this for a bit over 40 man-hours.

    Tim

  2. #2
    Join Date
    Feb 2003
    Posts
    51
    This location in MSDN gives the best example of how this would be done.

    http://msdn.microsoft.com/library/de...maDatabase.asp

    Essentially, what you do is read the image data into a Byte array, create a MemoryStream from the Byte array, and finally use Image.FromStream with the MemoryStream you created as an argument.

    e.g.
    Assuming ds is a populated dataset, tablecounter is the table in the dataset that you want to look at, rowcounter is the row in the table that you want to look at, imagecolumn is the column in the row where the image is, and PictureBox1 is the picture box where you want the image:

    Dim byteArrayName() As Byte

    byteArrayName = CType(ds.Tables(tablecounter).Rows(rowcounter).Item(imagecolumn), Byte())

    Dim dataStreamName As New System.IO.MemoryStream(byteArrayName)

    PictureBox1 = Image.FromStream(dataStreamName)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured