7 Replies - 2771 Views - Last Post: 09 October 2012 - 12:19 AM Rate Topic: -----

#1 arsalankhanzada  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 10-September 12

Retreiving image from database

Posted 02 October 2012 - 06:32 AM

i want to display image in image control from sql server database in asp.net....
how can i do this task.......kindly help me out.....
i have search this problem in many web but i couldnt found any solution....
thanks.....
Is This A Good Question/Topic? 0
  • +

Replies To: Retreiving image from database

#2 h4nnib4l  Icon User is offline

  • The Noid
  • member icon

Reputation: 1181
  • View blog
  • Posts: 1,675
  • Joined: 24-August 11

Re: Retreiving image from database

Posted 02 October 2012 - 07:09 AM

Are you saying the image itself is stored in the DB, or just the path to the image?
Was This Post Helpful? 0
  • +
  • -

#3 arsalankhanzada  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 10-September 12

Re: Retreiving image from database

Posted 03 October 2012 - 01:15 AM

hello friends......
i have image control and i want to display image on it from database........
i am getting image id from previous page as cookie and passing to compare with image id...
i have this code and this is working well without any error......but not showing image in image control.....
kindly solve my problem........
thanks ......
regards arsalan...
     protected void Page_Load(object sender, EventArgs e)
            {
                string picturevalue=Request.Cookies["picture_id"].Value.ToString();
                DataTable dt = new DataTable();
                con = new SqlConnection(constr);
                string qstring = "select ID,ProductImage from Shirt_Product";
                SqlDataAdapter sda = new SqlDataAdapter(qstring,con);
                sda.Fill(dt);
                int a = dt.Rows.Count;
                for (int i = 0; i < a; i++)
                {
                    if (Convert.ToString(i) == picturevalue)
                    {
                        Image1.ImageUrl = dt.Rows[i]["ProductImage"].ToString();
                        
                    }
                }


Was This Post Helpful? 0
  • +
  • -

#4 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 267
  • View blog
  • Posts: 1,476
  • Joined: 07-April 08

Re: Retreiving image from database

Posted 03 October 2012 - 05:31 AM

What is stored in the ProductImage column in your database? The problem your going to run into is that if you are using Absolute paths i.e. C:\images\thisimage.png then it will not show it as the user that runs the app pool would need to have access to each of the parent directories. It is better to use relative paths to the images like so: ~/Images/thisimage.png.

This post has been edited by rgfirefly24: 03 October 2012 - 05:32 AM

Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9197
  • View blog
  • Posts: 34,551
  • Joined: 12-June 08

Re: Retreiving image from database

Posted 03 October 2012 - 10:02 AM

Let's not create duplicate topics.. merging.
Was This Post Helpful? 0
  • +
  • -

#6 arsalankhanzada  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 10-September 12

Re: Retreiving image from database

Posted 06 October 2012 - 12:33 AM

i have stored images in DB ... and i want to display that image on image control simply.......
Was This Post Helpful? 0
  • +
  • -

#7 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 267
  • View blog
  • Posts: 1,476
  • Joined: 07-April 08

Re: Retreiving image from database

Posted 08 October 2012 - 06:56 AM

since your storing them in the database you'll have to have an intermediary page to display them. Basically create an .aspx page that retrieves the images from the database based off a querystring or what have you. Set the content type of this page to be the type of image. I.E. jpg, png, ect. You then do a Response.BinaryWrite using the image as the stream.

EX:

//Code to retrieve image to a datareader (We'll call this page ImageRetrieve.aspx

do(reader.Read())
Response.ContentType = "image/jpeg"; //image/png for a png file
Response.BinaryWrite(reader.Item("Image"));




Now to set the Image control you'd do this:

Image.ImageURL = "ImageRetrieve.aspx?id=" + ImageID;


Was This Post Helpful? 0
  • +
  • -

#8 arsalankhanzada  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 10-September 12

Re: Retreiving image from database

Posted 09 October 2012 - 12:19 AM

Thanks rgfirefly24.now my porblem is solved by you.....
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1