将客户端图片保存到数据库

1.将客户端图片保存到数据库

 protected void Button4_Click(object sender, EventArgs e)
        {
            HttpPostedFile upPhoto = f_1.PostedFile;
            int upPhotoLength = upPhoto.ContentLength;
            byte[] PhotoArray = new Byte[upPhotoLength];
            Stream PhotoStream = upPhoto.InputStream;
            PhotoStream.Read(PhotoArray, 0, upPhotoLength);///////////// 

            string constr = "Data Source=192.168.10.58; Initial Catalog=saveImagesDB; user ID=sa; password=123; pooling=true;";
            string strSQL = "insert into T_image(id,imageobj)values(@id,@imageobj)";
            SqlConnection con = new SqlConnection(constr);
            SqlCommand com3 = new SqlCommand(strSQL, con);
            Random ro = new Random();
            string id = ro.Next(1000).ToString();
            com3.Parameters.Add("@id", SqlDbType.VarChar).Value = id;
            com3.Parameters.Add("@imageobj", SqlDbType.Image).Value = PhotoArray;
            com3.Connection.Open();
            com3.ExecuteNonQuery();
        }
原文地址:https://www.cnblogs.com/Evan-Pei/p/3314343.html