求助:如何将Byte[]保存成Word文档Oracle 10g 中的Blob字段如果存储的是图片,可以方便地用Image对象转化成本地图片(如代码中注释的两行).
问题是如果BLOB字段中存储的是Word文档,如何取回在本地打开或保存.
谢谢 private void GetDBBlob(string strSelectCommandText)
{
DataSet ds = new DataSet(); ds = SelectOracle(strSelectCommandText, "T_ZTWJ");
int rowCount = ds.Tables[0].Rows.Count; if (rowCount > 0)
{
Byte[] byteBLOBData = new Byte[0];
byteBLOBData = (Byte[])(ds.Tables[0].Rows[0]["WJNR"]); System.IO.MemoryStream stmBLOBData = new System.IO.MemoryStream(byteBLOBData);
//pictureBox1.Image = System.Drawing.Image.FromStream(stmBLOBData);
//return System.Drawing.Image.FromStream(stmBLOBData);
}
else
{
//return null;
}
}
问题是如果BLOB字段中存储的是Word文档,如何取回在本地打开或保存.
谢谢 private void GetDBBlob(string strSelectCommandText)
{
DataSet ds = new DataSet(); ds = SelectOracle(strSelectCommandText, "T_ZTWJ");
int rowCount = ds.Tables[0].Rows.Count; if (rowCount > 0)
{
Byte[] byteBLOBData = new Byte[0];
byteBLOBData = (Byte[])(ds.Tables[0].Rows[0]["WJNR"]); System.IO.MemoryStream stmBLOBData = new System.IO.MemoryStream(byteBLOBData);
//pictureBox1.Image = System.Drawing.Image.FromStream(stmBLOBData);
//return System.Drawing.Image.FromStream(stmBLOBData);
}
else
{
//return null;
}
}
private void GetDBBlob(string strSelectCommandText)
{
DataSet ds = new DataSet(); ds = SelectOracle(strSelectCommandText, "T_ZTWJ");
int rowCount = ds.Tables[0].Rows.Count; if (rowCount > 0)
{
Byte[] byteBLOBData = new Byte[0];
byteBLOBData = (Byte[])(ds.Tables[0].Rows[0]["WJNR"]); string fileName = "mydoc.doc";
System.IO.FileStream fs=new System.IO.FileStream(fileName,System.IO.FileMode.Create,System.IO.FileAccess.Write);
System.IO.BinaryWriter bw= new System.IO.BinaryWriter(fs);
bw.Write(byteBLOBData); bw.Flush();
fs.Flush();
bw.Close();
fs.Close();
}
else
{
//return null;
}
}
byteBLOBData = (Byte[])(ds.Tables[0].Rows[0]["WJNR"]);
===============
这个写法有问题。应该直接写
Byte[] byteBLOBData = (Byte[])(ds.Tables[0].Rows[0]["WJNR"]);