<% @Page Language="C#" Debug="true"%>
<% @Import Namespace="System.IO" %>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.SqlClient" %>

<script runat="server">



private void Page_Load(Object sender, EventArgs e) {

string sql="SELECT PaintingNumber, PaintingImage, FileType FROM tImg WHERE PaintingNumber = '" + Request.QueryString["PaintingNumber"] + "'";
SqlConnection connection = new SqlConnection("server=*****,Port#; uid=*****; pwd=*****; Database=*****");

SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
SqlDataReader dr = command.ExecuteReader();

if(dr.Read()){
Response.AddHeader("Content-Type",dr["FileType"].ToString());
Response.BinaryWrite( (byte[]) dr["PaintingImage"] );
}
dr.Close();
connection.Close();

}
</script>