//upload image public void OnUpload(Object sender, EventArgs e) { int len = Upload.PostedFile.ContentLength; byte[] pic = new byte[len]; Upload.PostedFile.InputStream.Read (pic, 0, len); SqlConnection connection = new SqlConnection (@"server=INDIA INDIA;database=iSense;uid=sa;pwd=india"); try { connection.Open (); SqlCommand cmd = new SqlCommand ("insert into Image " + "(Picture, Comment) values (@pic, @text)", connection); cmd.Parameters.Add ("@pic", pic); cmd.Parameters.Add ("@text", Comment.Text); cmd.ExecuteNonQuery (); } finally { connection.Close (); } } //load image private void Page_Load(object sender, System.EventArgs e) { MemoryStream stream = new MemoryStream (); SqlConnection connection = new SqlConnection (@"server=INDIA INDIA;database=iSense;uid=sa;pwd=india"); try { connection.Open (); SqlCommand command = new SqlCommand ("select Picture from Image where id"], connection); byte[] image = (byte[]) command.ExecuteScalar (); stream.Write (image, 0, image.Length); Bitmap bitmap = new Bitmap (stream); Response.ContentType = "image/gif"; bitmap.Save (Response.OutputStream, ImageFormat.Gif); } catch { string strblandImagePath = Server.MapPath(""); strblandImagePath += "NoImg.gif"; FileStream FileBlandImagestream = File.OpenRead(strblandImagePath); Bitmap bitImage = new Bitmap(FileBlandImagestream); Response.ContentType = "image/gif"; bitImage.Save(Response.OutputStream, ImageFormat.Gif); } finally { connection.Close (); stream.Close (); } }