Storing of image in DB using open file dialog box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajasekar s
    New Member
    • Feb 2012
    • 3

    Storing of image in DB using open file dialog box

    I want to store an image from PC to ms sql db , I want the details of the coding from the first step. From getting the image to converting to bytes and then storing, Can anyone please provide me the coding part of it..
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    While I personally don't like the practice of storing actual images in the database (way too much overhead, and if SQL goes down then you cannot display your images) but that's your decision.

    Given that I think this may help

    Comment

    • rajasekar s
      New Member
      • Feb 2012
      • 3

      #3
      Hi , thanks. But can i get the c # coding..
      And also If storing in Db is overload , Then which is the best way to do it.

      Comment

      • PsychoCoder
        Recognized Expert Contributor
        • Jul 2010
        • 465

        #4
        First, I'm not going to convert the code to C# for you, you will learn nothing.

        Best way, if this is an ASP.NET application then store the images in a folder and the path to the image in your database.

        Comment

        • rajasekar s
          New Member
          • Feb 2012
          • 3

          #5
          K sir, Thanks for your reply, I ll learn the C # coding part on my own. Thanks a lot.

          Comment

          • Newface
            New Member
            • Feb 2012
            • 16

            #6
            RAJASEKAR S,I too came across this issue and got it resolved in the following way
            1.datatype of the image column-image
            2.in aspx.cs page
            HttpPostedFile uploadedImage=n ull;
            byte[] imageData=null;
            if (cmdBrowsePhoto .PostedFile != null)
            {
            imageData = new byte[cmdBrowsePhoto. PostedFile.Cont entLength];
            uploadedImage = cmdBrowsePhoto. PostedFile;
            uploadedImage.I nputStream.Read (imageData, 0, (int)cmdBrowseP hoto.PostedFile .ContentLength) ;
            }
            and in parameter:
            cmd.Parameters. Add(new SqlParameter("@ photo", imageData));
            Please do let me know if it is workin for you or not!

            Comment

            Working...