|
-
Feb 17th, 2007, 01:55 AM
#1
Thread Starter
Lively Member
DataGrig with OleDbDataAdapter. How may I read BLOB
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
-
Feb 17th, 2007, 05:36 AM
#2
Addicted Member
Re: DataGrig with OleDbDataAdapter. How may I read BLOB
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
- cha0s4u ENJOI
Do Remember to RATE a post if it helps u,
Ratings encrougage those who Know enough,to help others 
-
Feb 17th, 2007, 08:08 PM
#3
Re: DataGrig with OleDbDataAdapter. How may I read BLOB
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
-
Feb 18th, 2007, 06:21 AM
#4
Thread Starter
Lively Member
Re: DataGrig with OleDbDataAdapter. How may I read BLOB
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)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|