I am using SQL Database,
In my example of my webpage, i got FileUpload & Image & Button Controls.
i wanna to know any tutorials or tricks from code behind that able to
upload the image file into my sql database and how to display the image in my Image controls?
P/S: For profile picture purpose

Recommended Answers

All 5 Replies

I think you may want to take this and resolve it in parts. For example, first clarify if you are planning to save the image in the database, or on the file system and the link in the database?

I've looked through my documentation and found a bookmark that I used quite a bit of time ago. I think it covers pretty much what you are asking for. take a look.

Save and Retrieve Images from the Database

now i am able to upload and display already.
But how can i self upload a image to database?

Self upload, you mean with no application?

Image img = new Image();
img.ImageUrl = "~/images/samples.png";

from code behind, how to insert to database?

        protected void uploadImage()
        {
            string strPhoto = AppDomain.CurrentDomain.BaseDirectory + "/images/Blank.png";
            FileStream fsPhoto = new FileStream(strPhoto, FileMode.Open, FileAccess.Read);
            Byte[] imageByte = new Byte[fsPhoto.Length];
            fsPhoto.Read(imageByte, 0, Convert.ToInt32(fsPhoto.Length));

            // SQL CODE
        }

Problem solved. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.