Stream fileDataStream = this.FileUpload1.PostedFile.InputStream;
byte[] fileData = new byte[fileDataStream.Length];
fileDataStream.Read(fileData, 0, fileData.Length);//读取流内容
fileDataStream.Seek(0, SeekOrigin.Begin);//设置流的位置
上面代码图片二进制流获取成功
下面是在Access数据库中保存二进制流,需要把保存二进制流字段设置为“OLE对象”类型
string strConn = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = {0}", Application.StartupPath + "\\Test.mdb");
OleDbConnection Conn = new OleDbConnection(strConn);
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = Conn;
cmd.CommandText = "insert into pic (img) values(@img)";
cmd.Parameters.Add("@img", OleDbType.Binary, Convert.ToInt32(fileData.Length)).Value = fileData;
Conn.Open();
cmd.ExecuteNonQuery();
cmd.Dispose();
Conn.Close();
Conn.Dispose();
如果给你带来帮助,欢迎微信或支付宝扫一扫,赞一下。