Hello! (VS 2005) I got a DataGrid and I'm using OleDbDataAdapter for to show selected records (by SQL) from mdb. One of fields is BLOB. How may I read it and show (bmp, jpeg, doc, xml files possible). Thanks a lot
Printable View
Hello! (VS 2005) I got a DataGrid and I'm using OleDbDataAdapter for to show selected records (by SQL) from mdb. One of fields is BLOB. How may I read it and show (bmp, jpeg, doc, xml files possible). Thanks a lot
Try reading the data and put that into an object type variable; then use an appropriate control like picturebox or something to show that data. (u might want to first Ctype the object into the resulting type)
HTH
A BLOB field will return a Byte array. The usual way to deal with that is to write it to a MemoryStream and then read from the stream into the appropriate object. For an Image you'd use Image.FromStream, while for XML code you could create an XmlTextReader. Her's an example where the BLOB contains an image:VB Code:
Using myMemoryStream As New IO.MemoryStream Dim data As Byte() = DirectCast(myDataRow("BLOB"), Byte()) myMemoryStream.Write(data, 0, data.Length) myMemoryStream.Seek(0, IO.SeekOrigin.Begin) Dim myImage As Image = Image.FromStream(myMemoryStream) End Using
Thank You. Your code gives an "Parameter is not valid." for both formats bmp and jpg.
After all, the only code that works but for bmp images is next:
Dim OriginalImage As Image = Nothing
Dim dt As New DataTable
dt = Me.SeniorMailDataSet.Description_of_messages
If dt.Rows.Count < 1 Then Return OriginalImage
Dim bytImage() As Byte
bytImage = CType(dt.Rows(row).Item(12), Byte())
Dim imgbytes(bytImage.Length - 79) As Byte
Array.Copy(bytImage, 78, imgbytes, 0, bytImage.Length - 78)
Dim strmImage As New MemoryStream(imgbytes)
OriginalImage = Image.FromStream(strmImage)