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 save image into sql server ?

how to save image into sql server ?

Scheduled Pinned Locked Moved C#
csharpdatabasesql-serversysadmintutorial
2 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.
  • X Offline
    X Offline
    xingselex
    wrote on last edited by
    #1

    my code is ..... Dim fs As FileStream = New FileStream(mImageFilePath.ToString(), FileMode.Open) ..... and i can only read image from ' mImageFilePath.ToString()'. Does C# has other way such read/ stream the image from PictureBox control ? so please tell me some guid line if u know ... thank :confused:

    L 1 Reply Last reply
    0
    • X xingselex

      my code is ..... Dim fs As FileStream = New FileStream(mImageFilePath.ToString(), FileMode.Open) ..... and i can only read image from ' mImageFilePath.ToString()'. Does C# has other way such read/ stream the image from PictureBox control ? so please tell me some guid line if u know ... thank :confused:

      L Offline
      L Offline
      Leonscape
      wrote on last edited by
      #2

      SQL Server stores bytes, so you need to save and read the bytes.

      // Turning img into bytes
      Bitmap bmp = new Bitmap( FILENAME );
      MemoryStream ms = new MemoryStream();
      bmp.Save( ms, SOMEIMAGEFORMAT );
      byte[] imgBytes = ms.ToArray();

      You can now save imgBytes to SQL using varbinary or image column types. to get it back

      // Turning the bytes back into an image
      byte[] imgBytes = DirectCast( row["IMAGECOLUMN"], byte());
      MemoryStream ms = new MemoryStream( imgBytes );
      Bitmap bmp = new Bitmap( ms );

      Using the wrong tool for the job is half the fun.

      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