Hi
Beginner here...
I want to display image thats stored in the SQL Database in a new page for now.
I got as far as the code below for displaying image stored in SQL Database.
Please advise. I just don't know the step after this. I looked at other examples and tried..but just couldn;t get it going. I want to show image in the very webpage.
Thanks in advance
public partial class ViewImage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{string connectionstring;
string sqlText = "SELECT Evidence,EvidenceContentType FROM [Complaint] where ID = 33";
connectionstring = ConfigurationManager.ConnectionStrings["COMPLAINTCon"].ConnectionString;
SqlConnection con = new SqlConnection(connectionstring);
SqlCommand command = new SqlCommand(sqlText, con);
//open the database and get a datareader
con.Open();
SqlDataReader dr =command.ExecuteReader();
if (dr.Read()) //yup we found our image
{
Response.ContentType = dr["EvidenceContentType"].ToString();
Response.BinaryWrite((byte[])dr["Evidence"]);
Response.Close();
}
con.Close();