I’m trying to upload docx document to Access database.
OleDbConnection conn = null;
OleDbDataReader reader = null;
try
{
conn = new OleDbConnection(
"Provider=Microsoft.ACE.OLEDB.12.0; " +
"Data Source=" + @"C:\AudSystem\Auditoru_sertifikacija2007.accdb");
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "insert into questions (Category, Question, Answers, CorrectAnswers, Comment, Reference, QuestionNumber, Changed, IsNew) values (@p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10)";
byte[] file = File.ReadAllBytes(@"C:\AudSystem\rez.docx");
cmd.Parameters.AddWithValue("@p2", 2);
cmd.Parameters.AddWithValue("@p3", file);
cmd.Parameters.AddWithValue("@p4", file);
cmd.Parameters.AddWithValue("@p5", "asd");
cmd.Parameters.AddWithValue("@p6", "fgh");
cmd.Parameters.AddWithValue("@p7", "zxc");
cmd.Parameters.AddWithValue("@p8", 1);
cmd.Parameters.AddWithValue("@p9", true);
cmd.Parameters.AddWithValue("@p10", true);
cmd.Connection = conn;
cmd.ExecuteNonQuery();
}
finally
{
if (reader != null) reader.Close();
if (conn != null) conn.Close();
}
All is fine, but when I open database table in design view, I see that in row is stored “Long binary data”, instead of “Microsoft word document”. If I save file to database through the Access form, file is stored as “Microsoft word document” and I can edit it using access form. So, how can I store programmaticly docx file to access OLE field as “Microsoft word document”?
In picture, I've saved same file in "Question" field by Access Form, but in "Answers" field by C# code.
Thanks.