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

时间:2019-04-03 01:29:54

标签: access-vba

我是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

1 个答案:

答案 0 :(得分:0)

Use this function to retrieve byte data for a specified file:

' 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
相关问题