首页 新闻 会员 周边 捐助

圖片存儲到Orcale數據庫?

0
悬赏园豆:20 [已解决问题] 解决于 2009-11-18 16:09

各位大俠好!

     請問一下關於圖片以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

找了半天也不知道該如何解決,哪位知道請告訴一下,謝謝啦!

soarfe的主页 soarfe | 初学一级 | 园豆:146
提问于:2009-11-16 13:37
< >
分享
最佳答案
0

看看,給

 

讀取和寫入圖片到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();
}
}
收获园豆:20
woody.wu | 老鸟四级 |园豆:3621 | 2009-11-16 16:15
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册