You need to embed an image into your webpage:
<img alt="" src="ImageFromDb.ashx" />
You then need to code to access and display the image.
In VS, right click your project, and select "Add new Item"
When the dialog appears, select "Generic Handler" from the list, and call it "InamgeFromDb"
Press [ENTER].
The code below will display an image dynamically:
<%@ WebHandler Language="C#" Class="ImageFromDb" %>
using System;
using System.Web;
using System.Data.SqlClient;
public class ImageFromDb : IHttpHandler
{
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
using (SqlConnection con = new SqlConnection(@"Data Source=GRIFFPC\SQLEXPRESS;Initial Catalog=myDatabase;Integrated Security=True"))
{
con.Open();
SqlCommand com = new SqlCommand("SELECT * FROM myTable WHERE id=1 AND Username='Hello'", con);
com.Parameters.AddWithValue("@DT", DateTime.Now);
SqlDataReader read = com.ExecuteReader();
while (read.Read())
{
object o = read["Image"];
if (!(o is DBNull))
{
context.Response.ContentType = "image/JPEG";
context.Response.BinaryWrite((byte[]) o);
}
}
}
}
}
You will have to modify this code to suit your database and user id system.