using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.Sql; using System.Data.SqlClient; using System.Drawing; using System.Drawing.Imaging; public partial class tootepilt : System.Web.UI.Page { void SaadaTyhiPilt() { Bitmap b = new Bitmap(200, 100); Graphics g = Graphics.FromImage(b); SolidBrush sulepea = new SolidBrush(Color.Green); g.DrawString("Pilti pole", new Font("times", 20), sulepea, new PointF(20, 20)); g.DrawLine(Pens.Red, 10, 50, 100, 50); b.Save(Response.OutputStream, ImageFormat.Gif); } protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["tooteid"]==null) { Response.Write("toote kood puudub"); Response.End(); } SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings[ "veebipoebaasConnectionString"].ConnectionString); SqlCommand cm=new SqlCommand("SELECT pildiDATA FROM tooted WHERE id=@id", cn); cn.Open(); cm.Parameters.AddWithValue("id", int.Parse(Request.QueryString["tooteid"])); byte[] vastus = cm.ExecuteScalar() as byte[]; if (vastus == null) { //Response.Write("pilt puudub"); SaadaTyhiPilt(); Response.End(); } Response.ContentType = "image/gif"; Response.BinaryWrite(vastus); Response.End(); } }