我把图片转换成二进制流保存到了数据库,怎么才可以把这二进制流的图片,从数据库里读出来并在窗体里显示出来呀,请高手指点指点~~
添加到数据库的:
OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+System.Web.HttpContext.Current.Server.MapPath("img.mdb"));
Stream FileStream=this.myFile.PostedFile.InputStream;
int FileLen=this.myFile.PostedFile.ContentLength;
byte[] FileData=new byte[FileLen];
int n = FileStream.Read(FileData,0,FileLen);
string strSql = "INSERT INTO tbImg (imgdata) VALUES (@imgdata)";
myConn.Open();
OleDbCommand myCommand = new OleDbCommand(strSql,myConn);
myCommand.Parameters.Add("@imgdata",OleDbType.Binary);
myCommand.Parameters["@imgdata"].Value = FileData;
int iout = myCommand.ExecuteNonQuery();
myConn.Close();
if (iout==1)
{
Response.Write("添加成功");
}
[此贴子已经被作者于2007-1-4 17:17:48编辑过]
显示的:
OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+System.Web.HttpContext.Current.Server.MapPath("img.mdb"));
string strSql = "select imgdata from tbImg where id=1";
myConn.Open();
OleDbCommand myCommand = new OleDbCommand(strSql,myConn);
OleDbDataReader myReader = myCommand.ExecuteReader();
if (myReader.Read())
{
Response.ContentType = "jpg";
Response.BinaryWrite((byte[])myReader["imgdata"]);
}
myReader.Close();
myConn.Close();