怎么才能把图片存入ORACLE数据库并且读出来呢?用。net2.0下开发 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1、建立bolb字段,用来存放图片2、然后用insert或者update 该字段,值为empty_blob()3、用UPDATEBLOB 更新字段=图片文件(在PB中先设一个BLOB类型的变量来读图片) 4、读取时用selectblob来读此字段 网上搜索到的一段用c#写的代码.写入BLOB string file_name = "D:\\20080523.jpg"; string conn_str = "Provider=OraOLEDB.Oracle.1;Password=agoodjob;Persist Security Info=True;User ID=ams;Data Source=ims;Extended Properties=";//Provider必須用OraOLEDB.Oracle.1 OleDbConnection cn = new OleDbConnection(conn_str); cn.Open(); OleDbCommand cmd = new OleDbCommand("UPDATE BLOB SET PHOTO = ? ",cn); cmd.Parameters.Add("PHOTO",OleDbType.Binary); FileStream fs = new FileStream(file_name, FileMode.OpenOrCreate, FileAccess.Read); byte[] MyData= new byte[fs.Length]; fs.Read(MyData, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); cmd.Parameters["PHOTO"].Value = MyData; try { int result = cmd.ExecuteNonQuery(); if(result<1) { OleDbCommand cmd1 = new OleDbCommand(" INSERT INTO BLOB (PHOTO) VALUES ( ? )",cn); cmd1.Parameters.Add("PHOTO",OleDbType.Binary); cmd1.Parameters["PHOTO"].Value = MyData; result = cmd1.ExecuteNonQuery(); } } catch(Exception e1) { Page.RegisterStartupScript("","<script language='javascript'>alert('"+e1.Message+"')</script>"); } finally { cn.Close(); }2.读取BLOB string conn_str = "Provider=OraOLEDB.Oracle.1;Password=agoodjob;Persist Security Info=True;User ID=ams;Data Source=ims;Extended Properties=";//Provider必須用OraOLEDB.Oracle.1 OleDbDataAdapter da = new OleDbDataAdapter(); DataSet ds = new DataSet(); OleDbConnection conn = new OleDbConnection(conn_str); OleDbCommand cmd = new OleDbCommand("SELECT PHOTO FROM WEB_DB.USERS WHERE USER_ID = 1", conn); da.SelectCommand = cmd; cmd.Connection.Open(); da.Fill(ds); byte[] img = new byte[0]; DataRow dr; dr = ds.Tables[0].Rows[0]; if (!ds.Tables[0].Rows[0]["PHOTO"].ToString().Equals("")) { img = (byte[])dr["PHOTO"]; } Response.ContentType= "image/*"; Response.BinaryWrite (img); conn.Close(); 大家帮忙分析一下,这条SQL语句的执行计划,谢了! 在PB中执行ORACLE存储过程有什么要求吗? 请问怎样解决“ora -10080:并非所有变量都已绑定”这个错误? 请教一条sql语句 如何大批量删除行? 清问:如何把sql server的数据库或者表 转换成 oracle的数据库 oracle怎样在触发器中取得应用程序名? sql语句 oracle某张表中索引混乱! USER_TAB_PARTITIONS 这个表可以被修改么?我想增加表的分区 !! 在库之间导表问题,急急 !! 在oracle存储过程中实现分区怎么写啊,想利用for循环实现
2、然后用insert或者update 该字段,值为empty_blob()
3、用UPDATEBLOB 更新字段=图片文件(在PB中先设一个BLOB类型的变量来读图片)
.写入BLOB string file_name = "D:\\20080523.jpg";
string conn_str = "Provider=OraOLEDB.Oracle.1;Password=agoodjob;Persist Security Info=True;User ID=ams;Data Source=ims;Extended Properties=";//Provider必須用OraOLEDB.Oracle.1
OleDbConnection cn = new OleDbConnection(conn_str);
cn.Open(); OleDbCommand cmd = new OleDbCommand("UPDATE BLOB SET PHOTO = ? ",cn);
cmd.Parameters.Add("PHOTO",OleDbType.Binary);
FileStream fs = new FileStream(file_name, FileMode.OpenOrCreate, FileAccess.Read);
byte[] MyData= new byte[fs.Length];
fs.Read(MyData, 0, System.Convert.ToInt32(fs.Length));
fs.Close(); cmd.Parameters["PHOTO"].Value = MyData;
try
{
int result = cmd.ExecuteNonQuery();
if(result<1)
{
OleDbCommand cmd1 = new OleDbCommand(" INSERT INTO BLOB (PHOTO) VALUES ( ? )",cn);
cmd1.Parameters.Add("PHOTO",OleDbType.Binary);
cmd1.Parameters["PHOTO"].Value = MyData;
result = cmd1.ExecuteNonQuery();
}
}
catch(Exception e1)
{
Page.RegisterStartupScript("","<script language='javascript'>alert('"+e1.Message+"')</script>");
}
finally
{
cn.Close();
}2.读取BLOB string conn_str = "Provider=OraOLEDB.Oracle.1;Password=agoodjob;Persist Security Info=True;User ID=ams;Data Source=ims;Extended Properties=";//Provider必須用OraOLEDB.Oracle.1
OleDbDataAdapter da = new OleDbDataAdapter();
DataSet ds = new DataSet();
OleDbConnection conn = new OleDbConnection(conn_str);
OleDbCommand cmd = new OleDbCommand("SELECT PHOTO FROM WEB_DB.USERS WHERE USER_ID = 1", conn);
da.SelectCommand = cmd;
cmd.Connection.Open();
da.Fill(ds); byte[] img = new byte[0];
DataRow dr;
dr = ds.Tables[0].Rows[0]; if (!ds.Tables[0].Rows[0]["PHOTO"].ToString().Equals(""))
{
img = (byte[])dr["PHOTO"];
} Response.ContentType= "image/*";
Response.BinaryWrite (img); conn.Close();