将客户端图片保存到数据库
2013-09-11 13:09 Evan.Pei 阅读(262) 评论(0) 收藏 举报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();
}
浙公网安备 33010602011771号