首页 > 解决方案 > 将 pdf 文件插入 SQL Server 链接数据库

问题描述

我是 Access 编程新手,尝试将.pdfWord 文档插入 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

标签: vbams-access

解决方案


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

' 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

推荐阅读