How to properly save a bitmap in a database in binary type, considering that image type is deprecated? RRS feed

  • Question

  • Greeting community

    This question is about SQL server 2012 express and .NET application.

    I have a need to store few dozen of pictures in database so they are indexed. Those are small pictures and are actually part of UI.

    I’ve never tried myself, but I saw in (older) samples with Northwind database that if you have image data type in your database and you drag it from your data source, you’ll automatically get a picture box bound to that data type, and you see the stored picture in your app.

    Considering that image data type in SQL server 2012 has been proclaimed as obsolete, I would like to know which data from one bitmap and in which order should be saved in binary or varbinary type so that could be directly bound to picture box.

    Thanks for any thoughts.

    • Moved by Bob Beauchemin Monday, March 18, 2013 1:49 PM Moved to the forum for SqlClient client-side code for best response
    Monday, March 18, 2013 2:24 AM


All replies

  • You can use varbinary(MAX) as a replcaement for image

    Please mark as answer, if this was it. Visit my SQL Server Compact blog

    Monday, March 18, 2013 6:04 PM
  • Hi Eric, thanks for taking the part.

    I do know that I have to use varbinary – that’s suggested in the manual. Only I don’t know exactly how. It’s probably my English, and I’ve been misunderstood again. I’ll try to give this question more clearer form.

    I have few dozens of bitmaps not photos (for UI elements, every one 16x16 pixels and 822 bytes long). So I could use varbinary(822). Now I load the picture from the file into picture box on my .NET app and it shows there.

    First question: how do I transfer those 822 bytes from the picture box to a byte array in order to save that array in my database?

    Second question: when I pull those 822 bytes from the database to a byte array, how do I push them into picture box in order to have a picture shown?

    Thanks for any idea.

    Wednesday, March 20, 2013 1:54 AM
    • Marked as answer by IvicaNesic Wednesday, March 20, 2013 1:17 PM
    Wednesday, March 20, 2013 9:19 AM
  • Thanks Erik.
    Wednesday, March 20, 2013 1:17 PM