Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am trying to get image saved in the database. i used the code below but it wont return image.
C#
if (Request.QueryString["ProductID"] != null)
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ProdDB"].ConnectionString);
    string query = "SELECT ProductID, ProductName, ProductImage FROM Product";

    SqlDataAdapter da = new SqlDataAdapter(query, con);
    DataTable dt = new DataTable();

    da.Fill(dt);
    for (int i = 0; i < dt.Rows.Count; i++ ){
        if (dt != null) {       
             Byte[] bytes = (Byte[])dt.Rows[i]["ProductImage"];     
            Response.Buffer = true;
            Response.Charset = "";
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = "Image/png";
            Response.AddHeader("content-disposition", "attachment;filename="
            + dt.Rows[i]["ProductName"].ToString());
            Response.BinaryWrite(bytes); 
            Response.Flush();    
        }      
    }  
    Response.Flush();
    Response.End ();
}

[Edit]Added Pre Tag : Amit Kumar[/Edit]
Posted
Updated 20-May-13 2:11am
v3

1 solution

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