using System;
using System.Collections;
using System.Configuration;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace DBImages
{
	/// <summary>
	/// Summary description for ViewImage.
	/// </summary>
	public class ViewImage : System.Web.UI.Page
	{
		public ViewImage()	{ 	}

		private void Page_Load(object sender, System.EventArgs e)
		{
			string ImageId = Request.QueryString["img"];
			string sqlText = "SELECT img_data, img_contenttype FROM Image WHERE img_pk = " + ImageId;

			SqlConnection connection = new SqlConnection( ConfigurationSettings.AppSettings["DSN"].ToString() );
			SqlCommand command = new SqlCommand( sqlText, connection);
			
			connection.Open();
			SqlDataReader dr = command.ExecuteReader();
			if ( dr.Read()) //yup we found our image
			{
				Response.ContentType = dr["img_contenttype"].ToString();
				Response.BinaryWrite( (byte[]) dr["img_data"] );
			}
				
			connection.Close();
		
		}
	}
}
