Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey guys..
I m working on a project..i m unable to store and retrieve image in database..
Can I store Images on Web server and retrieve from their and perfom the required operations?????

thanx
Posted

Have a look at this: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^] - dont' worry about the name, it explains how not to do it, then covers the code to do it properly.

Retrieving them is (generally) pretty trivial as well:
C#
using (SqlConnection con = new SqlConnection(GenericData.DBConnection))
    {
    con.Open();
    using (SqlCommand cmd = new SqlCommand("SELECT ImageData FROM Images WHERE Id=@ID", con))
        {
        cmd.Parameters.AddWithValue("@ID", Id);
        SqlDataReader r = cmd.ExecuteReader();
        if (r.Read())
            {
            MemoryStream ms = new MemoryStream((byte[])r["ImageData"]);
            MyImage = Image.FromStream(ms);
            }
        }
    }
You can then use MyImage in your application via whatever control you require.
 
Share this answer
 
Hi...
See this link, may its help full to u.
Save and retriving images in local Folder from sql database[^]
Thank u.
 
Share this answer
 
Comments
santosh_k 2-Dec-13 1:47am    
HI! u can use this link...
http://stackoverflow.com/questions/16261566/saving-and-retrieving-of-images-from-sql-server-database-using-c-sharp
[no name] 2-Dec-13 2:17am    
Thanks.
The best way to store and retrieve image is to store image in physically in web server and only the link for that image in the database.
 
Share this answer
 
hello mr. C@dER@j...


How can i implement this.... ???
 
Share this answer
 
Comments
Shweta N Mishra 29-Oct-14 11:01am    
You would have to do the following
1. Create a virtual directory on your reporting Server.
2. Store all the images under that virtual directory(Folder)
3. Store the name of images to you DB
4. In you application while displaying the image pick the relevant name of image and give a link to that image pointing to the physical location where you have created virtual directory.

But not allow the images to be visible for a particular user which you can you use in app also, other wise you image link will be open to all.
[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900