所以我尝试寻找解决方案,我经常发现DAO作为解决方案,但我不确切知道如何使用它,我的意思是要导入什么,还是需要dll?
答案 0 :(得分:1)
以下VB.NET代码使用DAO添加名为" Sample.pdf"的文件。到名为[MyTable]的表中名为[AttachmentsField]的字段中:
Imports Microsoft.Office.Interop.Access.Dao
Module Module1
Sub Main()
' this code requires that your project have the following COM Reference:
' Microsoft Office 14.0 Access Database Engine Object Library
Dim dbe As New DBEngine
Dim db As Database = dbe.OpenDatabase("C:\Users\Public\Database1.accdb")
Dim rstRecord As Recordset = db.OpenRecordset( _
"SELECT * FROM MyTable WHERE ID=1", _
RecordsetTypeEnum.dbOpenDynaset)
rstRecord.Edit()
Dim rstAttachments As Recordset2 = rstRecord.Fields("AttachmentsField").Value
rstAttachments.AddNew()
Dim AttachmentData As Field2 = rstAttachments.Fields("FileData")
AttachmentData.LoadFromFile("C:\Users\Gord\Desktop\Sample.pdf")
rstAttachments.Update()
rstAttachments.Close()
rstRecord.Update()
rstRecord.Close()
db.Close()
End Sub
End Module