我在检索存储的BLOB文档(Word文档存储为字节)和在Microsoft Word中打开该文档的原始副本时遇到问题。我通过使用DataGridView中列出的数据行的ID号,通过Oracle查询选择blob列。到目前为止,我的代码是读取BLOB文件:
private void btnOpenCV_Click(object sender,EventArgs e)
{
string fileName = Path.GetTempFileName() + ".docx";
int id = 0;
OracleConnection con = new OracleConnection(oradb);
con.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = con;
try
{
foreach (DataGridViewCell selectedCell in dgvSearchJob.SelectedCells)
{
if (selectedCell.Selected)
id = Convert.ToInt32(dgvSearchJob.CurrentRow.Cells[0].Value);
cmd.CommandText = "SELECT CandidateCV FROM Candidate WHERE CandidateID like '" + id + "'";
cmd.CommandType = CommandType.Text;
using(OracleDataReader oradr = cmd.ExecuteReader())
{
while (oradr.Read())
{
int size = 1024 * 1024;
byte[] buffer = new byte[size];
int readBytes = 0;
int index = 0;
using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
while ((readBytes = (int)oradr.GetBytes(0, index, buffer, 0, size)) >0)
{
fs.Write(buffer, 0, readBytes);
index += readBytes;
}
}
}
oradr.Close();
}
}
Process prc = new Process();
prc.StartInfo.FileName = fileName;
prc.Start();
}
catch (ArgumentException ex)
{
MessageBox.Show("Error: " + ex.Message);
}
catch (OracleException ex1)
{
MessageBox.Show("Error: " + ex1.Message);
}
catch (Exception ex2)
{
MessageBox.Show("Error: " + ex2.Message);
}
finally
{
cmd.Dispose();
con.Dispose();
}
}
此执行返回异常“系统找不到指定的文件”,我不知道为什么。欢迎任何建议。