要將文件存入數據庫,你可以使用VBA來執行以下步驟:
Dim conn As Object
Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\path\to\your\database.accdb;"
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
Dim file As Object
Set file = fs.OpenTextFile("C:\path\to\your\file.txt", 1)
Dim fileContent As String
fileContent = file.ReadAll
file.Close
Dim sql As String
sql = "INSERT INTO files (fileContent) VALUES (?)"
Dim cmd As Object
Set cmd = CreateObject("ADODB.Command")
With cmd
.ActiveConnection = conn
.CommandText = sql
.Parameters.Append .CreateParameter("fileContentParam", 204, 1, Len(fileContent), fileContent)
.Execute
End With
conn.Close
這些是將文件存入數據庫的基本步驟。你可以根據你所使用的數據庫類型和表結構進行適當的修改。