Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. get byte[] from a database

get byte[] from a database

Scheduled Pinned Locked Moved Database
databasequestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sasuko
    wrote on last edited by
    #1

    I've saved an image (converting in byte[]) inside a field of my database, now i would read the database getting these bytes[] and convertering into the original image... I use this code: OleDbDataReader myReader; .... .. instance myReader here... .... myCommand.ExecuteReader(); MemoryStream myStream; int buffersize = 300000; // doubt n°2 = but if my image is bigger of 300000 ??? Byte[] outbyte = new Byte[299999]; myStream = new MemoryStream(outbyte, 0, 300000, true); myReader.GetBytes(5, 0, outbyte, 0, buffersize); myStream.Flush(); // am i just deleting all bytes unused? pictureBox1.Image = Image.FromStream(myStream); myStream.Close(); but this code doesn't work, where do i wrong?

    S D 2 Replies Last reply
    0
    • S Sasuko

      I've saved an image (converting in byte[]) inside a field of my database, now i would read the database getting these bytes[] and convertering into the original image... I use this code: OleDbDataReader myReader; .... .. instance myReader here... .... myCommand.ExecuteReader(); MemoryStream myStream; int buffersize = 300000; // doubt n°2 = but if my image is bigger of 300000 ??? Byte[] outbyte = new Byte[299999]; myStream = new MemoryStream(outbyte, 0, 300000, true); myReader.GetBytes(5, 0, outbyte, 0, buffersize); myStream.Flush(); // am i just deleting all bytes unused? pictureBox1.Image = Image.FromStream(myStream); myStream.Close(); but this code doesn't work, where do i wrong?

      S Offline
      S Offline
      Sasuko
      wrote on last edited by
      #2

      I've tried to change the code in this way: MemoryStream myStream; Byte[] outbyte = (Byte[])myReader["Image"]; myStream = new MemoryStream(outbyte); pictureBox1.Image = Image.FromStream(myStream); myStream.Close(); but this doesn't work too.

      1 Reply Last reply
      0
      • S Sasuko

        I've saved an image (converting in byte[]) inside a field of my database, now i would read the database getting these bytes[] and convertering into the original image... I use this code: OleDbDataReader myReader; .... .. instance myReader here... .... myCommand.ExecuteReader(); MemoryStream myStream; int buffersize = 300000; // doubt n°2 = but if my image is bigger of 300000 ??? Byte[] outbyte = new Byte[299999]; myStream = new MemoryStream(outbyte, 0, 300000, true); myReader.GetBytes(5, 0, outbyte, 0, buffersize); myStream.Flush(); // am i just deleting all bytes unused? pictureBox1.Image = Image.FromStream(myStream); myStream.Close(); but this code doesn't work, where do i wrong?

        D Offline
        D Offline
        David Salter
        wrote on last edited by
        #3

        Have a look at http://www.hostingphpbb.com/forum/viewtopic.php?t=15&mforum=databasefaq[^]


        Database FAQ

        L 1 Reply Last reply
        0
        • D David Salter

          Have a look at http://www.hostingphpbb.com/forum/viewtopic.php?t=15&mforum=databasefaq[^]


          Database FAQ

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Yes i did, but when i use (Byte[])cmd.ExexuteScalar() i get only 18 byte at the place of 17322 that is my image, why?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups