Vb.net 如何向access数据库的附件列进行读写附件,比如PDF文件
发布网友
发布时间:2022-04-27 06:00
我来回答
共2个回答
热心网友
时间:2023-09-12 03:03
可以使用OLE 去添加和下载附件追问怎么操作
追答。。。我找下代码
热心网友
时间:2023-09-12 03:04
我用的是VS2010。首先,在安装时,必须把VSTO安装上。其次,必须引用DAO,全名叫Microsoft.office.interop.access.。可以用import关键字引用,也可以直接在项目属性中去引用。最后,使用DAO就可以实现Access的附件上传和下载了。如何上传下载,还是比较复杂的,建议去Access的帮助中查看DAO的详细使用方法。
以下是别人的代码,可以参考下-----------------------
Dim DatabasePath As String = "C:\Users\...\Documents\My Database\Access\Attachment.accdb"
Dim AccessEngine As New Microsoft.Office.Interop.Access.Dao.DBEngine
Dim SourceRecordset As Microsoft.Office.Interop.Access.Dao.Recordset
Dim AttachmentRecordset As Microsoft.Office.Interop.Access.Dao.Recordset
Dim db As Microsoft.Office.Interop.Access.Dao.Database = AccessEngine.OpenDatabase(DatabasePath)
SourceRecordset = db.OpenRecordset("SELECT * FROM Table1 WHERE ID = 1")
AttachmentRecordset = SourceRecordset.Fields("MyAttachments").Value While Not AttachmentRecordset.EOF
Dim AttachmentFileName As String = AttachmentRecordset.Fields("FileName").Value.ToString
Dim AttachmentPath As String = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) & "\Test\" & AttachmentFileName
AttachmentRecordset.Fields("FileData").SaveToFile(AttachmentPath)
AttachmentRecordset.MoveNext()
End While
SourceRecordset.Close()
SourceRecordset = Nothing
AttachmentRecordset = Nothing
db.Close()
db = Nothing