Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
I am new to ASP.net. In my project i want to showing image on the web page.But this condition done by using image tag.But i want to show image from SQL server database.Here i'm using the table image_loads have the columns are mentioned below.
Table name:img_loads

img_recid INT
img_src IMAGE

How to show the image from img_src column.

Please give me advice how to solve it...
Posted
Updated 12-May-14 2:31am
v2
Comments
V. 12-May-14 8:10am    
Where are you stuck? getting the image out of the database? Showing an image on the page ?
Please elaborate where you have a problem and what you've tried so far. (Please update the question, don't hit reply)

 
Share this answer
 
v2
Hi,

As per my understanding regarding your problem you should take data type of img_src is varchar.
In this column you should save only path of the image. and Image should be physically saved in your project directory.

But if you can not change the data type of img_sr column and want to store image in database in form of bytes then following article will help you

http://www.aspsnippets.com/Articles/Display-Images-from-SQL-Server-Database-using-ASP.Net.aspx
http://www.dotnetfox.com/articles/store-and-retrieve-image-from-database-in-Asp-Net-1113.aspx
 
Share this answer
 
Check http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.image(v=vs.110).aspx for the Image control in Asp.Net


At first I thought you could assign a bitmap image to the control, try to find that first (I couldn't find it immediately.)

Next are the subproblems you need to solve.
1. get the image from the database.
You'll need to get the database value into a bitmap [^]or Image [^]object. If you receive the resultset, the object containing the image is a byte array (byte []). Look at the Stream[^] class.

2. Once you have an image you can assign it to the control (if you can find that option) or alternatively you can write it to a temp folder and provide the uri to the Image control or write an HTML img tag. In the latter case you can just convert the resultset object directly to stream and write to file. The trouble with this second method is you need to find a way to also delete the created resources for example on session end.

I would create a small prototype and try step by step beginning by getting the byte array from the resultset and converting it A to a stream (write to file and check in windows explorer) and B to an Image or Bitmap object. Secondly try to convert that image to a control that can be shown on a web page. If that doesn't work, write to file and dynamically provide link in the web page. Thirdly, in the session end event cleanup the generated files. (The session object is still known at that point so you can keep the generated filenames in the session object. Beware of naming collisions when working with multiple files for multiple users...

Hope this helps.
 
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