Column Name | Datatype | Purpose |
ID | Integer | identity column Primary key |
IMGTITLE | Varchar(50) | Stores some user friendly title to identity the image |
IMGTYPE | Varchar(50) | Stores image content type. This will be same as recognized content types of ASP.NET |
IMGDATA |
Image | Stores actual image or binary data. |
Stream imgdatastream = File1.PostedFile.InputStream;www.c hinaitpower.comlOPhU7 int imgdatalen = File1.PostedFile.ContentLength;www.c hinaitpower.comlOPhU7 string imgtype = File1.PostedFile.ContentType;www.c hinaitpower.comlOPhU7 string imgtitle = TextBox1.Text;www.c hinaitpower.comlOPhU7 byte[] imgdata = new byte[imgdatalen];www.c hinaitpower.comlOPhU7 int n = imgdatastream.Read(imgdata,0,imgdatalen);www.c hinaitpower.comlOPhU7 string connstr=www.c hinaitpower.comlOPhU7 ((NameValueCollection)Context.GetConfigwww.c hinaitpower.comlOPhU7 ("appSettings"))["connstr"];www.c hinaitpower.comlOPhU7 SqlConnection connection = new SqlConnection(connstr);www.c hinaitpower.comlOPhU7 SqlCommand command = new SqlCommandwww.c hinaitpower.comlOPhU7 ("INSERT INTO ImageStore(imgtitle,imgtype,imgdata)www.c hinaitpower.comlOPhU7 VALUES ( @imgtitle, @imgtype,@imgdata )", connection );www.c hinaitpower.comlOPhU7 www.c hinaitpower.comlOPhU7 SqlParameter paramTitle = new SqlParameterwww.c hinaitpower.comlOPhU7 ("@imgtitle", SqlDbType.VarChar,50 );www.c hinaitpower.comlOPhU7 paramTitle.Value = imgtitle;www.c hinaitpower.comlOPhU7 command.Parameters.Add( paramTitle);www.c hinaitpower.comlOPhU7 www.c hinaitpower.comlOPhU7 SqlParameter paramData = new SqlParameterwww.c hinaitpower.comlOPhU7 ( "@imgdata", SqlDbType.Image );www.c hinaitpower.comlOPhU7 paramData.Value = imgdata;www.c hinaitpower.comlOPhU7 command.Parameters.Add( paramData );www.c hinaitpower.comlOPhU7 www.c hinaitpower.comlOPhU7 SqlParameter paramType = new SqlParameterwww.c hinaitpower.comlOPhU7 ( "@imgtype", SqlDbType.VarChar,50 );www.c hinaitpower.comlOPhU7 paramType.Value = imgtype;www.c hinaitpower.comlOPhU7 command.Parameters.Add( paramType );www.c hinaitpower.comlOPhU7 www.c hinaitpower.comlOPhU7 connection.Open();www.c hinaitpower.comlOPhU7 int numRowsAffected = command.ExecuteNonQuery();www.c hinaitpower.comlOPhU7 connection.Close();www.c hinaitpower.comlOPhU7 |
private void Page_Load(object sender, System.EventArgs e)www.c hinaitpower.comlOPhU7 {www.c hinaitpower.comlOPhU7 string imgid =Request.QueryString["imgid"];www.c hinaitpower.comlOPhU7 string connstr=((NameValueCollection)www.c hinaitpower.comlOPhU7 Context.GetConfig("appSettings"))["connstr"];www.c hinaitpower.comlOPhU7 string sql="SELECT imgdata, imgtype FROM ImageStore WHERE id = "www.c hinaitpower.comlOPhU7 + imgid;www.c hinaitpower.comlOPhU7 SqlConnection connection = new SqlConnection(connstr);www.c hinaitpower.comlOPhU7 SqlCommand command = new SqlCommand(sql, connection);www.c hinaitpower.comlOPhU7 connection.Open();www.c hinaitpower.comlOPhU7 SqlDataReader dr = command.ExecuteReader();www.c hinaitpower.comlOPhU7 if(dr.Read())www.c hinaitpower.comlOPhU7 {www.c hinaitpower.comlOPhU7 Response.ContentType = dr["imgtype"].ToString();www.c hinaitpower.comlOPhU7 Response.BinaryWrite( (byte[]) dr["imgdata"] );www.c hinaitpower.comlOPhU7 }www.c hinaitpower.comlOPhU7 connection.Close();www.c hinaitpower.comlOPhU7 }www.c hinaitpower.comlOPhU7 |
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |