AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 display image in table control
Posted by Baheer on  1/9/2008 4:54:05 AM Category: Asp.Net 2.0
Add to my favorites
Email to friend
how to retrieve image from database and display in table control using asp.net in c#?

Post Your Reply Post New Question

 Viewer's Reply
Retreive Image From Database to Display in Image Control
Answered By Moderator1 on 6/18/2010 8:47:59 AM
Hi,

Actually Image stored in Database cannot be retrieved directly. You need to convert it into array of bytes to display it in the Image Control or any Image control that is placed inside the Table Control.

By using the record unique Id you need to retreive the image from another aspx page as follows. Before that you need to set the Image control ImageUrl property as below,

ImageUrl= "GetImageFromDb.aspx?ImageId=1"

Then in the code behind of the GetImageFromDb.aspx you need to write the below code in the page load event,

string sql = "Select * from ImagesList Where ImageID=@ImageID";
SqlDataAdapter da = new SqlDataAdapter(sql, ConfigurationManager.ConnectionStrings("TestConnectionString").ConnectionString);
DataTable dt = new DataTable();
da.SelectCommand.Parameters.Add("@ImageID", SqlDbType.Int).Value = Request("Id");
da.Fill(dt);
Context.Response.ContentType = dt.Rows(0)("ImageType").ToString();
Context.Response.BinaryWrite((byte[])dt.Rows(0)("ImageContent"));
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
SearchSAP
Building a Web Application Security Program
Windows 8: 50 Questions and Answers You Need to Make a Decision (Normally $9.95)