入库:
Stream sr = File1.PostedFile.InputStream;
byte[] buffer = new byte[size];
sr.Read(buffer, 0, size);
//然后把buffer里的数据写到数据库就OK
出库:(直接显示在一个页面里)
SqlConnection con = new SqlConnection(conStr);
con.Open();
SqlCommand cmd = new SqlCommand("select * from Image where
ID=@ID", con);
cmd.Parameters.Add(new SqlParameter("@ID", id));
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
Response.ContentType = "Image/Jpeg";
Response.AddHeader("Content-Dispositon", "attachment;filename=" + dr["name"].ToString());
Response.AddHeader("Content-Length", dr["size"].ToString());
int size = Convert.ToInt32(dr["size"]);
byte[] buffer = new byte[size];
dr.GetBytes(4, 0, buffer, 0, size);
Response.BinaryWrite(buffer);
con.Close();