如何读写Oracle中的BLOB数据 我有A和B两个表,字段相同,我想把A表中的BLOB字段值读出来,再放到B表中有没有不操作文件的方法,网上好多都是从文件读取。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用OracleClient OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["NEWOracleConn"].ToString()); OracleCommand cmd = new OracleCommand("UPDATE TUSER SET PHOTO=:photo WHERE userid=:id", conn); Console.WriteLine(cmd.CommandText); cmd.Parameters.Add("photo",OracleType.Blob); cmd.Parameters["photo"].Value = photo; cmd.Parameters.Add("id", OracleType.Number); cmd.Parameters["id"].Value = id; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); Byte[] blob = null; FileStream fs = null; const string sConn = "server=(local);Initial Catalog=Northwind;UID=ctester;PWD=password"; try { SqlConnection conn = new SqlConnection(sConn); SqlCommand cmd = new SqlCommand("SELECT Picture FROM Categories WHERE CategoryName='Builder'", conn); cn.Open(); SqlDataReader sdr = cmd.ExecuteReader(); sdr.Read(); blob = new Byte[(sdr.GetBytes(0, 0, null, 0, int.MaxValue))]; sdr.GetBytes[0, 0, blob, 0, blob.Length); sdr.Close(); conn.Close(); fs = new FileStream("c:\\Builder.doc", FileMode.Create, FileAccess.Write); fs.Write(blob, 0, blob.Length); fs.Close(); } catch (SqlException e){ Console.WriteLine("SQL Exception: " + e.Message); } catch (Exception e) { Console.WriteLine("Exception: "+ e.Message); } 裝ORACLE 提供的OO4O 安裝後會有DEMO CS程序打包安装后,快捷方式右键没有“以管理员身份运行”的选项 如何在WebBrowser中模拟点击由Div生成的“确定”按钮 C# session 串值的问题,有那位高手解决? 我晕死! C#引用C++ Dll问题 位、字节、字符、字串、进制?? 高手请进,一个小问题折磨了我一天 C#中如何调用C++编写的DLL c#Web编程中有没有现成的队列可用? 关于ListBox的分页显示问题?? windows mobile6.0开发过程中的属性问题? 获取类型长度问题
OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["NEWOracleConn"].ToString());
OracleCommand cmd = new OracleCommand("UPDATE TUSER SET PHOTO=:photo WHERE userid=:id", conn);
Console.WriteLine(cmd.CommandText);
cmd.Parameters.Add("photo",OracleType.Blob);
cmd.Parameters["photo"].Value = photo;
cmd.Parameters.Add("id", OracleType.Number);
cmd.Parameters["id"].Value = id;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
Byte[] blob = null;
FileStream fs = null;
const string sConn = "server=(local);
Initial Catalog=Northwind;
UID=ctester;PWD=password";
try {
SqlConnection conn = new SqlConnection(sConn);
SqlCommand cmd = new SqlCommand("SELECT Picture FROM Categories WHERE CategoryName='Builder'", conn);
cn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
blob = new Byte[(sdr.GetBytes(0, 0, null, 0, int.MaxValue))];
sdr.GetBytes[0, 0, blob, 0, blob.Length);
sdr.Close();
conn.Close();
fs = new FileStream("c:\\Builder.doc", FileMode.Create, FileAccess.Write);
fs.Write(blob, 0, blob.Length);
fs.Close();
}
catch (SqlException e)
{
Console.WriteLine("SQL Exception: " + e.Message);
}
catch (Exception e)
{ Console.WriteLine("Exception: "+ e.Message);
}