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. General Programming
  3. C#
  4. how to get Image from DataSet

how to get Image from DataSet

Scheduled Pinned Locked Moved C#
databasegraphicshelptutorial
4 Posts 2 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.
  • G Offline
    G Offline
    goldsoft
    wrote on last edited by
    #1

    hi i have DataSet that contain Image. i need to save this Image to File. i try this: SQL = ItemCode,PIC from ROW; dsView = new DataSet(); adp = new SqlCeDataAdapter(SQL, Conn); adp.Fill(dsView, "ROW"); adp.Dispose(); foreach (DataRow R in dsROW.Tables[0].Rows) { ItemCode = R["ItemCode"].ToString().Trim() ; TEMP = R["PIC"].ToString().Trim(); Image image = R["PIC"] as Image; if(image != null) { MemoryStream ms = new MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] imagedata = ms.ToArray(); } but image Always is null and in TEMP i see System.Byte[] need some help, thanks

    J 1 Reply Last reply
    0
    • G goldsoft

      hi i have DataSet that contain Image. i need to save this Image to File. i try this: SQL = ItemCode,PIC from ROW; dsView = new DataSet(); adp = new SqlCeDataAdapter(SQL, Conn); adp.Fill(dsView, "ROW"); adp.Dispose(); foreach (DataRow R in dsROW.Tables[0].Rows) { ItemCode = R["ItemCode"].ToString().Trim() ; TEMP = R["PIC"].ToString().Trim(); Image image = R["PIC"] as Image; if(image != null) { MemoryStream ms = new MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] imagedata = ms.ToArray(); } but image Always is null and in TEMP i see System.Byte[] need some help, thanks

      J Offline
      J Offline
      John Torjo
      wrote on last edited by
      #2

      You need to treat R["PIC"] as a byte array. See this: https://social.msdn.microsoft.com/Forums/en-US/4d25dec3-8ce1-40c3-9234-771317e95a14/get-bytearray-from-datarow?forum=adodotnetdataproviders[^] You need to

      byte[] myImage = (byte[]) R["PIC"];
      MemoryStream ms = new MemoryStream(myImage);
      Bitmap mybmp = new Bitmap(ms);

      Best, John

      -- LogWizard Meet the Log Viewer that makes monitoring log files a joy!

      G 1 Reply Last reply
      0
      • J John Torjo

        You need to treat R["PIC"] as a byte array. See this: https://social.msdn.microsoft.com/Forums/en-US/4d25dec3-8ce1-40c3-9234-771317e95a14/get-bytearray-from-datarow?forum=adodotnetdataproviders[^] You need to

        byte[] myImage = (byte[]) R["PIC"];
        MemoryStream ms = new MemoryStream(myImage);
        Bitmap mybmp = new Bitmap(ms);

        Best, John

        -- LogWizard Meet the Log Viewer that makes monitoring log files a joy!

        G Offline
        G Offline
        goldsoft
        wrote on last edited by
        #3

        thank for the help ! i try this and i got: InvalidCastException i work on C# Windows-Mobile thanks

        J 1 Reply Last reply
        0
        • G goldsoft

          thank for the help ! i try this and i got: InvalidCastException i work on C# Windows-Mobile thanks

          J Offline
          J Offline
          John Torjo
          wrote on last edited by
          #4

          That means the field is not a blob (thus, it can't be converted to a byte array). Please check the data type of your "pic" Best, John

          -- LogWizard Meet the Log Viewer that makes monitoring log files a joy!

          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