各位大俠好!
請問一下關於圖片以Blod類型存儲到資料庫中,代碼如下:
byte[] fix_img;//二進制字符流
sp[1] = new OracleParameter("vi_fix_img", OracleType.Blob, fix_img.Length);
sp[1].Value = fix_img;
但在執行oraComm.ExecuteNonQuery();總是出項如下錯誤:
ORA-01460: unimplemented or unreasonable conversion requested
找了半天也不知道該如何解決,哪位知道請告訴一下,謝謝啦!
看看,給
讀取和寫入圖片到oracle
string constring = "user id=work;data source=woodywork;password=woody";
//此處寫入ORACLE
string FILENAME = Server.MapPath("UpFile/") + "TEST.jpg";
FileStream imageFileStream = File.Open(FILENAME, FileMode.Open, FileAccess.Read);
byte[] Content = new byte[imageFileStream.Length];
imageFileStream.Read(Content, 0, Content.Length);
imageFileStream.Close();
using (OracleConnection conn = new OracleConnection(constring))
{
try
{
string SQL = " INSERT INTO WOODY (NAME,CONTENT)VALUES(:NAME,:CONTENT)";
OracleCommand cmd = new OracleCommand(SQL, conn);
conn.Open();
OracleParameter PAR_NAME = new OracleParameter("NAME", OracleType.VarChar);
PAR_NAME.Value = "WOODY";
cmd.Parameters.Add(PAR_NAME);
OracleParameter PAR_CONTENT = new OracleParameter("CONTENT", OracleType.Blob);
PAR_CONTENT.Value = Content;
cmd.Parameters.Add(PAR_CONTENT);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
}
finally
{
conn.Close();
}
}
//讀取並使用
using (OracleConnection conn = new OracleConnection(constring))
{
string SQL = " SELECT NAME,CONTENT FROM WOODY ";
OracleCommand cmd = new OracleCommand(SQL, conn);
try
{
conn.Open();
OracleDataReader reader = cmd.ExecuteReader();
System.Drawing.Image image;
while (reader.Read())
{
string Name = reader.GetString(0);
OracleLob MyClob = reader.GetOracleLob(1);
StreamReader streamreader = new StreamReader(MyClob, Encoding.Unicode);
image = System.Drawing.Image.FromStream(streamreader.BaseStream); ;
image.Save(Server.MapPath("upFile/" + Name+".jpg"));
}
reader.Close();
}
catch
{
}
finally
{
conn.Close();
}
}