Results 1 to 4 of 4

Thread: DataGrig with OleDbDataAdapter. How may I read BLOB

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    97

    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

  2. #2
    Addicted Member cha0s4u's Avatar
    Join Date
    Apr 2005
    Location
    new Delhi - 1ND1A
    Posts
    209

    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

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Using myMemoryStream As New IO.MemoryStream
    2.     Dim data As Byte() = DirectCast(myDataRow("BLOB"), Byte())
    3.  
    4.     myMemoryStream.Write(data, 0, data.Length)
    5.     myMemoryStream.Seek(0, IO.SeekOrigin.Begin)
    6.  
    7.     Dim myImage As Image = Image.FromStream(myMemoryStream)
    8. End Using
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    97

    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
  •  



Click Here to Expand Forum to Full Width