Click to See Complete Forum and Search --> : database images..... sigh


Tlawson
June 9th, 2002, 03:40 PM
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

Rube74
February 25th, 2003, 03:52 PM
This location in MSDN gives the best example of how this would be done.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvssamp/html/vbcs_ReadandWriteImagesfromaDatabase.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)