Asp.Net News
Free Tech Magazines
Asp.Net Web Hosting
Suggest Us
Link to Us
Feeds Subscription
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 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

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");
Context.Response.ContentType = dt.Rows(0)("ImageType").ToString();
Post Your Reply If you still have problem, post it again under this reply for better response.

Sponsored by
Many .NET teams are underperforming, is yours?
Programmers Heaven C# School Book - Free 338 Page eBook
Integrating Silverlight 4 with SharePoint 2010 - Free 42 Page Sample Chapter