954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Display Image from database

Hi,

First of all am new 2 .net concepts.

I want to retrieve the image details from the database and to display it in the screen.
eg:
1. I have stored the img details as

<asp:Image ID="Image1" ImageUrl="imgs/Titanic.bmp" style="width: 88px; height: 64px"  runat="server"  />


inside the db.
2.i used some query to retrieve this information.
3.Then i tried to display this infrmation using response.write and other tingz ,,but notg happenz..

plz tell me me how to do this.....

Manuz
Junior Poster
122 posts since Oct 2008
Reputation Points: 12
Solved Threads: 24
 

To display image on your form you can use the Picturebox control and the Image class:

Image yourImage = Image.FromFile(pathOfYourImage);
            pictureBox1.Image = yourImage;


Is that what you are looking for?

Antenka
Posting Whiz
362 posts since Nov 2008
Reputation Points: 293
Solved Threads: 82
 

and just to supplement anteka, in case you are having trouble reading it from the database

SqlCommand cmd = new SqlCommand("select imagecolumn from tablename where id = 1");
SqlDataReader dataReader = cmd.ExecuteReader();
byte[] imageBytes = (byte[]) imageReader.GetValue(0);

MemoryStream ms = new MemoryStream(imageBytes);

FileStream fs = File.OpenWrite(imagePath);
fs.Write(ms.GetBuffer(), 0, ms.Position());

//now we have it on the filesystem
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
 

The RbmBinaryImage control will help you display images directly from your database. You could bind the Image field directly to the ImageContent property, also you could specify whether you want the display to be as a thumbnail or not and provide the thumbnail size.

to get it go to http://www.ramymostafa.com/?p=187

Regards
Ramy Mostafa
Hi,

First of all am new 2 .net concepts.

I want to retrieve the image details from the database and to display it in the screen.
eg:
1. I have stored the img details as

<asp:Image ID="Image1" ImageUrl="imgs/Titanic.bmp" style="width: 88px; height: 64px"  runat="server"  />


inside the db.
2.i used some query to retrieve this information.
3.Then i tried to display this infrmation using response.write and other tingz ,,but notg happenz..

plz tell me me how to do this.....

rmostafa
Newbie Poster
2 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You