将pdf文件插入SQL Server链接数据库

问题描述 投票:0回答:1

我是Access的新手,并试图将.pdf和Word文档插入SQL Server链接数据库并遇到问题。我需要一些提示来开始这个。可以一些帮助。

Dim f As Object
Dim sFile As String
Dim fld_path As String
Dim fld_file As String

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim Sql As String
Dim Code As String


 FileToBlob = "C:\temp\1.pdf"

Sql = "INSERT INTO dbo_Doc (Doc) VALUES (FileToBlob)"

DoCmd.RunSQL Sql
access-vba
1个回答
0
投票

使用此函数检索指定文件的字节数据:

' fPath is the path to the file
Function FileToBlob(fPath As String) As Variant
    Dim fileNum As Long
    Dim b() As Byte

    fileNum = FreeFile
    Open fPath For Binary As fileNum
        ReDim b(LOF(fileNum))
        Get fileNum, , b()
    Close fileNum

    FileToBlob = b
End Function
© www.soinside.com 2019 - 2024. All rights reserved.