using System; using System.Data; using System.Configuration; using System.Collections; using System.Collections.Generic; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; using System.IO; using System.Drawing; public partial class Default11 : System.Web.UI.Page { SqlConnection cc = new SqlConnection("server=nilu-pc;initial catalog=project;integrated security=true"); DataSet ds = new DataSet(); public SqlCommand cmd = new SqlCommand(); SqlDataAdapter adp; protected void Page_Load(object sender, EventArgs e) { cc.Open(); } protected void Button1_Click(object sender, EventArgs e) { BinaryReader rr=new BinaryReader(FileUpload1.PostedFile.InputStream); byte[] img = rr.ReadBytes(FileUpload1.PostedFile.ContentLength); string sql = "insert into image values(1,@IMG)"; adp = new SqlDataAdapter(sql, cc); adp.SelectCommand.Parameters.Add("@IMG",SqlDbType.VarBinary,8000).Value=img; adp.Fill(ds,"image"); } protected void showinimagecontrol_Click(object sender, EventArgs e) { System.Drawing.Image imaf = null; SqlCommand command = cc.CreateCommand(); command.CommandText = "select IMG from image WHERE ID=1"; //adp = new SqlDataAdapter(sql,cc); //adp.Fill(ds, "image byte[] imageData = (byte[])command.ExecuteScalar(); // byte[] imgdata = (byte[])ds.Tables[0].Rows[0][1]; Response.Write(imageData); MemoryStream mm = new MemoryStream(imageData, 0, imageData.Length); imaf = System.Drawing.Image.FromStream(mm); imaf.Save(Server.MapPath("Photo0074.jpg")); Image1.ImageUrl = "Photo0074.jpg"; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)