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. C# to SQL

C# to SQL

Scheduled Pinned Locked Moved Database
databasecsharpsql-serversysadminhelp
6 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.
  • P Offline
    P Offline
    Peter Greenall
    wrote on last edited by
    #1

    Can anyone tell me how to store an image from a c# windows form, to a MS SQL Server Database. I've been struggling with this for some time now - please help me if you can. Thanks in advice, Peter

    G M 2 Replies Last reply
    0
    • P Peter Greenall

      Can anyone tell me how to store an image from a c# windows form, to a MS SQL Server Database. I've been struggling with this for some time now - please help me if you can. Thanks in advice, Peter

      G Offline
      G Offline
      Guillermo Rivero
      wrote on last edited by
      #2

      First, you must convert your image into a bit stream, then save it into a nimage field in your SQL Server. 1. Search about transforming your image into a stream. 2. Search about storing streams into SQL Server. It's not that hard. Free your mind...

      P 1 Reply Last reply
      0
      • G Guillermo Rivero

        First, you must convert your image into a bit stream, then save it into a nimage field in your SQL Server. 1. Search about transforming your image into a stream. 2. Search about storing streams into SQL Server. It's not that hard. Free your mind...

        P Offline
        P Offline
        Peter Greenall
        wrote on last edited by
        #3

        I was going along these lines, but part of my problem is that the ways I have seen to do this involve reading the image from a file to put it into a stream, then saving it as an array of bytes. This can then be reversed at the other end. I need to be able to create a byte-array of a System.Drawing.Image.Bitmap variable, to reduce the overhead of saving the file first. As for storing in the SQL server, I did consider using a web-service which re-constructed the stream before saving in the server - not sure if this is possible. There is an 'image' data type in MS SQL, and I was hoping it was going to be as easy as doing an INSERT non-query directly from my c# application, but there seems to be serialization issues here because the System.Drawing.Image.Bitmap data tybe does not implement IConvertable (or something like that). Thanks for your reply - if anyone can help me any further with this problem, I would be MOST grateful. Thanks peter ;P

        G 1 Reply Last reply
        0
        • P Peter Greenall

          I was going along these lines, but part of my problem is that the ways I have seen to do this involve reading the image from a file to put it into a stream, then saving it as an array of bytes. This can then be reversed at the other end. I need to be able to create a byte-array of a System.Drawing.Image.Bitmap variable, to reduce the overhead of saving the file first. As for storing in the SQL server, I did consider using a web-service which re-constructed the stream before saving in the server - not sure if this is possible. There is an 'image' data type in MS SQL, and I was hoping it was going to be as easy as doing an INSERT non-query directly from my c# application, but there seems to be serialization issues here because the System.Drawing.Image.Bitmap data tybe does not implement IConvertable (or something like that). Thanks for your reply - if anyone can help me any further with this problem, I would be MOST grateful. Thanks peter ;P

          G Offline
          G Offline
          Guillermo Rivero
          wrote on last edited by
          #4

          Take a look at Bitmap.Save method. You can save it to a memory stream. Then send that memory to the DB. There is a formatter in the System.Web namespace, named LosFormatter (No documentation), that converts any byte array into a string. You can use it to serialize it into a string, then send it thru the webservice. I recomend you to use a Store Procedure to store the Image in the DB instead of a direct INSERT. ;) Free your mind...

          1 Reply Last reply
          0
          • P Peter Greenall

            Can anyone tell me how to store an image from a c# windows form, to a MS SQL Server Database. I've been struggling with this for some time now - please help me if you can. Thanks in advice, Peter

            M Offline
            M Offline
            Mazdak
            wrote on last edited by
            #5

            C# Photo Album Viewer[^] Mazy No sig. available now.

            P 1 Reply Last reply
            0
            • M Mazdak

              C# Photo Album Viewer[^] Mazy No sig. available now.

              P Offline
              P Offline
              Peter Greenall
              wrote on last edited by
              #6

              Thankyou all for your help - Im a good few steps closer to my solution. Thanks again, Peter

              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