图片上传到数据库

it2022-05-21  69

 protected void btnAdd_Click(object sender, EventArgs e)        {            string connstr = "data source=连接到计算机;initial catalog=student;User Id=sa;password=123";            using (SqlConnection conn = new SqlConnection(connstr))            {                conn.Open();                using (SqlCommand cmd = conn.CreateCommand())                {                    //获得图象并把图象转换为byte[]                     HttpPostedFile upPhoto = UpPhoto.PostedFile;                    int upPhotoLength = upPhoto.ContentLength;                    byte[] PhotoArray = new Byte[upPhotoLength];                    Stream PhotoStream = upPhoto.InputStream;                    PhotoStream.Read(PhotoArray, 0, upPhotoLength);                    cmd.CommandText = "insert into boke (FIamge) values(@FImage)";                    cmd.Parameters.Add("@FImage", SqlDbType.Image);                    cmd.Parameters["@FImage"].Value = PhotoArray;                    cmd.ExecuteNonQuery();                }            }        }

转载于:https://www.cnblogs.com/qzc900809/archive/2013/01/04/2844919.html

相关资源:java实现上传图片存入到数据库

最新回复(0)