zimcoder Level: VB Lord

 Registered: 27-10-2003 Posts: 225
|
Problem displaying images from database
Hi all
I have uploaded images to an SQL Server database in binary format and would like to display the images in my page via a datalist. I have followed some of the examples online but i have not been successful
here is the Coode that is reading my database and attempting to display the images ..
public class ReturnImage : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
string productID = Request.QueryString["productID"].ToString();
int prodID = Int32.Parse(productID);
string sqlText = "Select ThumbNail,ContentType FROM Prducts WHERE ProductID="+prodID;
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand command = new SqlCommand(sqlText,conn);
conn.Open();
SqlDataReader reader = command.ExecuteReader();
if(reader.Read()) {
Response.Clear();
Response.ContentType = reader["ContentType"].ToString();
Response.BinaryWrite((byte[])reader["ThumbNail"]);
Response.Close();
}
reader.Close();
conn.Close();
}
} |
this page is called from the img tag that is meant to diplay the actual image.
<img height=75 src='ReturnImage.aspx?productID=<%# DataBinder.Eval(Container.DataItem, "ProductID") %>' width=100 Border=1>
the enctype on the form has been set like this enctype="multipart"
am i missing something?
____________________________
BrainBench ADO.NET and ASP.NET Certified Developer
 
|