locked
Photo linking to the user RRS feed

  • Question

  • I have created a GUID and the photos are stored to a image folder but now I have many users in the database. So when each user logged in and want to to upload a photo, how do I store the photo so that I can know that the photo belong to that particular user?
    Saturday, October 22, 2011 7:59 AM

Answers

  • Add a varchar(max) column in table or create a new table for storing image and userId. Once that is done you can use below sample to see how to save and retrive.
    http://www.codeproject.com/KB/database/Store_images_in_SQL_Serve.aspx

    Balmukund Lakhani | Please mark solved if I've answered your question, vote for it as helpful to help other user's find a solution quicker
    --------------------------------------------------------------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
    --------------------------------------------------------------------------------
    My Blog | Team Blog | @Twitter
    Saturday, October 22, 2011 8:05 AM
  • Add a varchar(max) column in table or create a new table for storing image and userId. Once that is done you can use below sample to see how to save and retrive.
    http://www.codeproject.com/KB/database/Store_images_in_SQL_Serve.aspx

    For storing pictures, I'd suggest varbinary(max), not varchar(max).

    However, I am not sure if this addresses tje original poster's
    question. I don't fully understand what he/she asks, so if this does
    not answer the real question, I suggest him/her to rephrase.


    Hugo Kornelis, SQL Server MVP
    My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
    • Proposed as answer by Peja TaoEditor Monday, October 24, 2011 9:10 AM
    • Marked as answer by Peja TaoEditor Wednesday, November 2, 2011 12:38 PM
    Saturday, October 22, 2011 9:25 AM

All replies

  • Add a varchar(max) column in table or create a new table for storing image and userId. Once that is done you can use below sample to see how to save and retrive.
    http://www.codeproject.com/KB/database/Store_images_in_SQL_Serve.aspx

    Balmukund Lakhani | Please mark solved if I've answered your question, vote for it as helpful to help other user's find a solution quicker
    --------------------------------------------------------------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
    --------------------------------------------------------------------------------
    My Blog | Team Blog | @Twitter
    Saturday, October 22, 2011 8:05 AM
  • Also http://www.sqlteam.com/article/images-and-sql-server
    Balmukund Lakhani | Please mark solved if I've answered your question, vote for it as helpful to help other user's find a solution quicker
    --------------------------------------------------------------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
    --------------------------------------------------------------------------------
    My Blog | Team Blog | @Twitter
    Saturday, October 22, 2011 8:06 AM
  • Add a varchar(max) column in table or create a new table for storing image and userId. Once that is done you can use below sample to see how to save and retrive.
    http://www.codeproject.com/KB/database/Store_images_in_SQL_Serve.aspx

    For storing pictures, I'd suggest varbinary(max), not varchar(max).

    However, I am not sure if this addresses tje original poster's
    question. I don't fully understand what he/she asks, so if this does
    not answer the real question, I suggest him/her to rephrase.


    Hugo Kornelis, SQL Server MVP
    My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
    • Proposed as answer by Peja TaoEditor Monday, October 24, 2011 9:10 AM
    • Marked as answer by Peja TaoEditor Wednesday, November 2, 2011 12:38 PM
    Saturday, October 22, 2011 9:25 AM
  • Thank you for your help. But is it a must to change it to byte?
    Saturday, October 22, 2011 9:30 AM
  • >Thank you for your help. But is it a must to change it to byte?

    If you want to store pictures in the database, then varchar(max) is
    the most appropriate type.

    If you store pictures in the file system and store only the path- and
    filename in the database, then varchar(n) with an appropriate value
    for n would be my choice. But in that case, you should really consider
    using FILESTREAM as an alternative - if you are running SQL Server
    2008 or 2008R@, that is.


    Hugo Kornelis, SQL Server MVP
    My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
    Saturday, October 22, 2011 9:42 AM
  • For storing pictures, I'd suggest varbinary(max), not varchar(max).
    Yes Hugo! As always, you are correct. It was a typo. Thanks for catching it.
    Balmukund Lakhani | Please mark solved if I've answered your question, vote for it as helpful to help other user's find a solution quicker
    --------------------------------------------------------------------------------
    This posting is provided "AS IS" with no warranties, and confers no rights.
    --------------------------------------------------------------------------------
    My Blog | Team Blog | @Twitter
    Saturday, October 22, 2011 10:18 AM
  • Actually I had created a table for storing imageid and the imagename. I need to change the image to thumbnail. And that thumbnail will be link to the userid. How can I do it?
    Friday, October 28, 2011 2:23 AM