1

I have been trying to figure out how to add an image to my database table, so when a query comes back with information it also provides an image. I see an image data type in SQL server 2008, but I cannot figure out what to do with byte[]. I was hoping to just link to an image in my project folder: images/item1.png

is this possible?

Thank you

deucalion0
  • 2,422
  • 9
  • 55
  • 99
  • 1
    _See Also: [Questions regarding SQL Server 2008 & Images](http://stackoverflow.com/search?q=[sql-server-2008]+storing+images), specifically: http://stackoverflow.com/questions/1071636/storing-images-on-a-database http://stackoverflow.com/questions/1252206/storing-images-in-sql-server http://stackoverflow.com/questions/7657771/storing-and-retrieving-images-in-database – Brad Christie Feb 03 '12 at 14:59
  • Why you want to store image into DB? If you store image into DB, it will increase DB size and slow when you retrieve records. Please check here.. http://blog.sqlauthority.com/2007/12/13/sql-server-do-not-store-images-in-database-store-location-of-images-url/ – Thit Lwin Oo Feb 03 '12 at 15:02
  • I actually do not want to store an image in the database, I already came across that article, I just don't know how to achieve that method. Thanks. Thanks for the links Brad Christie – deucalion0 Feb 03 '12 at 15:05

2 Answers2

1

You can insert the images as byte[], and set the pointing column type to BLOB. Then you can insert and retrieve data from that table.

Eric Frick
  • 847
  • 1
  • 7
  • 18
  • Could you provide me with some examples of this, it sounds like an ideal soultion! – deucalion0 Feb 03 '12 at 15:05
  • unfortunately, i work only in asp.net. The solution will be: 1) get the image from you want to get it. 2) transform it to byte array. 3) send it to the database. (that's for inserting) And then backwards for retrieving it. 1)select image from table, 2)convert byte array to image. 3) Display image. – Eric Frick Feb 03 '12 at 15:58
1

You can save the file in database by converting it to byte[]. I guess you figured this out.

but I cannot figure out what to do with byte[]

For this please go through this post which explains how to get image from byte array.

Hope this works for you.

Community
  • 1
  • 1
Amar Palsapure
  • 9,590
  • 1
  • 27
  • 46
  • You need to accept the answers if you are satisfied with them. Seen you have asked 4 question and didn't accept any of the answer. Please read the [FAQ](http://stackoverflow.com/faq#howtoask). – Amar Palsapure Feb 03 '12 at 15:16
  • Thanks for letting me know, I will make sure I accept an answer in future. – deucalion0 Feb 03 '12 at 15:19