我现在用Oracle数据库。这么才能实现和MSsql一样把整个图片存入数据里面呢?希望高手们帮忙!谢谢了!
------解决方案--------------------------------------------------------
看看上次某某兄弟贴上来的oracle写图片的例子, 你改一改
图片存在long raw类型的字段里
Stream imgdatastream = File1.PostedFile.InputStream;
int imgdatalen = File1.PostedFile.ContentLength;
string imgtype = File1.PostedFile.ContentType;
string imgtitle = TextBox1.Text;
byte[] imgdata = new byte[imgdatalen];
int n = imgdatastream.Read(imgdata,0,imgdatalen);
OracleCommand myCommand = new OracleCommand( "INSERT INTO uu(ufiletitle, ufiletype, ufiledata) VALUES (:imgtitle,:imgtype, :imgdata) ");
myCommand.Connection = new OracleConnection( "Data Source=OA;User ID=jack;Password=dian;Integrated Security=no; ");
myCommand.CommandType = CommandType.Text;
OracleParameter paramtitle = new OracleParameter( ":imgtitle ", OracleType.VarChar, 50);
paramtitle.Value = imgtitle;
myCommand.Parameters.Add( paramtitle );
OracleParameter paramtype = new OracleParameter( ":imgtype ", OracleType.VarChar, 50);
paramtype.Value = imgtype;
myCommand.Parameters.Add( paramtype );
OracleParameter paramData = new OracleParameter( ":imgdata ", OracleType.LongRaw);
paramData.Value = imgdata;
myCommand.Parameters.Add( paramData );
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
显示的:
OracleCommand myCommand = new OracleCommand( "SELECT ufiletype,ufiledata FROM UU where ufiletitle= 'bnm ' ");
myCommand.Connection = new OracleConnection( "Data Source=OA;User ID=jack;Password=dian;Integrated Security=no; ");
myCommand.CommandType = CommandType.Text;
myCommand.Connection.Open();
OracleDataReader dr =myCommand.ExecuteReader();
if(dr.Read())
{
//Stream imgdatastream = dr[ "ufiledata "];
Response.ContentType = dr[ "ufiletype "].ToString();
Response.BinaryWrite((byte[])dr[ "ufiledata "]);
//Response.Write(dr[ "ufiledata "]);
}
myCommand.Connection.Close();