C#语言中图片该怎样保存到数据库中?把代码告诉我
2014-02-21
展开全部
//上传
System.Web.HttpPostedFile myFile = this.Request.Files[0];
//读取到数组里面
System.IO.Stream mystream = myFile.InputStream;
byte[] Buffer = new byte[myFile.ContentLength];
mystream.Read(Buffer,0,myFile.ContentLength);
//打开数据库
OracleConnection cn = new OracleConnection(ConfigurationSettings.AppSettings["sysDSN"]);
cn.Open();
//用参数方式写入数据库
OracleCommand myComm = cn.CreateCommand();
string sql = "insert into tmp(tmp_id,tmp_blob) values(tmp_seq.nextval,:tmp_blob)";
myComm.CommandText = sql;
myComm.Parameters.Add(":tmp_blob",OracleType.Blob,Buffer.Length).Value = Buffer;
myComm.ExecuteNonQuery();
System.Web.HttpPostedFile myFile = this.Request.Files[0];
//读取到数组里面
System.IO.Stream mystream = myFile.InputStream;
byte[] Buffer = new byte[myFile.ContentLength];
mystream.Read(Buffer,0,myFile.ContentLength);
//打开数据库
OracleConnection cn = new OracleConnection(ConfigurationSettings.AppSettings["sysDSN"]);
cn.Open();
//用参数方式写入数据库
OracleCommand myComm = cn.CreateCommand();
string sql = "insert into tmp(tmp_id,tmp_blob) values(tmp_seq.nextval,:tmp_blob)";
myComm.CommandText = sql;
myComm.Parameters.Add(":tmp_blob",OracleType.Blob,Buffer.Length).Value = Buffer;
myComm.ExecuteNonQuery();
2014-02-21
展开全部
System.IO.MemoryStream ms = new System.IO.MemoryStream();
pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] x=ms.ToArray()
再将x存入存入SQL server的image字段中
pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] x=ms.ToArray()
再将x存入存入SQL server的image字段中
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询