将exe文件插入数据库 [英] Inserting exe file to database
本文介绍了将exe文件插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将一个exe文件更新到blobfield数据库.代码如下
Hi,
i am updating an exe file to blobfield database. Code is as below
FileStream fls = new FileStream(@filepath, FileMode.OpenOrCreate, FileAccess.Read);
byte[] blob = new byte[fls.Length];
fls.Read(blob, 0, System.Convert.ToInt32(fls.Length));
fls.Close();
string query = "update employee set doc = :BlobParameter ";
OracleParameter blobParameter = new OracleParameter();
blobParameter.OracleType = OracleType.Blob;
blobParameter.ParameterName = "BlobParameter";
blobParameter.Value = blob;
OracleCommand cmd = new OracleCommand(query,conn);
cmd.Parameters.Add(blobParameter);
cmd.ExecuteNonQuery();
conn.Close();
conn.Dispose();
}
但是,当使用下面的代码进行检索时,它将无法正常工作
But when retreive with the code as below, it does not work properly
string sql = "Select doc from employee where docId = ''121''";
OracleCommand cmd = new OracleCommand(sql, conn);
OracleDataReader dataReader = cmd.ExecuteReader();
dataReader.Read();
OracleLob blob = dataReader.GetOracleLob(0);
dataReader.Close();
// Create a byte array
byte[] byteData = new byte[0];
// fetch the value of Oracle parameter into the byte array
byteData = (byte[])blob.Value;
// get the length of the byte array
int ArraySize = byteData.GetUpperBound(0);
// Write the Blob data fetched from database to the filesystem at the destination
FileStream fs1 = new FileStream(FilePath, FileMode.OpenOrCreate , FileAccess.Write);
fs1.Write(byteData, 0, ArraySize);
fs1.Close();
请建议还有其他unicode概念.
在此先感谢
Please suggess that is there any other unicode concept.
Thanks in advance
推荐答案
为什么要使用文件流?
Why play with filestreams?
byte[] data = File.ReadAllBytes(path);
...
File.WriteAllBytes(path, data);
那样,您就没有在做或暗示任何Unicode或其他转换.然后将字节存储起来并作为二进制字节数据检索.
That way, you aren''t doing or implying any Unicode, or other conversions. The bytes are then just stored and retrieved as binary byte data.
这篇关于将exe文件插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文