以编程方式管理的Microsoft Access附件类型的字段.NET字段、附件、类型、方式

由网友(喵个汪)分享简介:进入加在2007年的版本,新的数据类型 - 附件类型。目前,我们正在与.NET 3.5(C#),使用Access 2007数据库WinForms应用程序。我们希望能够通过的WinForms界面添加新的附件。我似乎无法找到如何插入或选择使用.NET附件数据的任何信息。我曾尝试使用DAO(12版),但它似乎并没有在这里讨论...

进入加在2007年的版本,新的数据类型 - 附件类型。目前,我们正在与.NET 3.5(C#),使用Access 2007数据库WinForms应用程序。我们希望能够通过的WinForms界面添加新的附件。我似乎无法找到如何插入或选择使用.NET附件数据的任何信息。我曾尝试使用DAO(12版),但它似乎并没有在这里讨论的SaveToFile或LoadFromFile方法:的 http://msdn.microsoft.com/en-us/library/bb258184.aspx

Access added a new data type in the 2007 version--the Attachment type. We are currently working on a WinForms application with .NET 3.5 (C#) that uses an Access 2007 database. We want to be able to add new attachments through the WinForms interface. I can't seem to locate any information on how to insert or select attachment data with .NET. I did try using DAO (version 12) but it didn't seem to have the SaveToFile or LoadFromFile methods discussed here: http://msdn.microsoft.com/en-us/library/bb258184.aspx

所以,我怎么能在与.NET附件得到什么呢?

So, how can I get at the attachments with .NET?

推荐答案

我终于得到这个使用参考Microsoft.Office.Interop.Access.Dao在C#中的工作。

I finally got this working in C# using a reference to Microsoft.Office.Interop.Access.Dao.

DBEngine dbe = new DBEngine();
Database db = dbe.OpenDatabase("C:SomeDatabase.accdb", false, false, "");
Recordset rs = db.OpenRecordset("SELECT * FROM TableWithAttachmentField", RecordsetTypeEnum.dbOpenDynaset, 0, LockTypeEnum.dbOptimistic);
rs.MoveFirst();
rs.Edit();
Recordset2 rs2 = (Recordset2)rs.Fields["AttachmentFieldName"].Value;
rs2.AddNew();

Field2 f2 = (Field2)rs2.Fields["FileData"];

f2.LoadFromFile("C:test.docx");
rs2._30_Update();
rs2.Close();

rs._30_Update();
rs.Close();

这将test.docx添加到表中的附件场AttachmentFieldNameTableWithAttachmentField。有一点要注意的是,在尝试两次添加相同的文件将抛出一个错误。

This will add test.docx to the Attachment field "AttachmentFieldName" in table "TableWithAttachmentField". One thing to note is that attempting to add the same file twice will throw an error.

阅读全文

相关推荐

最新文章