我试图弄清楚将mailitem.attachments推送到SQL BLOB字段的方法。我想我需要做一个流或二进制,但我不是100%肯定?
Public Sub BLOB(avMailitem As Variant)
Dim gobjApp As Object
Dim gobjOriginalWorkItem As Object
Dim gcnnSqlServerConnection As ADODB.Connection
Dim grsBLOB As ADODB.Recordset
Dim vCPDID As Variant
Dim vAttach As Variant
Dim i As Integer
Dim iTotal As Integer
Set gcnnSqlServerConnection = New ADODB.Connection
gcnnSqlServerConnection.ConnectionString = "Provider=sqloledb; Server=XXXXXXXXXX; Database=XXXXXX; uid=XXX; pwd=XXX; "
gcnnSqlServerConnection.Open
Set grsBLOB = New ADODB.Recordset
vSql = "dbo.BLOB"
grsBLOB.Open vSql, gcnnSqlServerConnection, adOpenDynamic, adLockOptimistic, adCmdTable
vCPDID = avMailitem.UserProperties.Add("CPDId", olText, True).Value
iTotal = avMailitem.Attachments.Count
i = 1
For i = 1 To iTotal
Set vAttach = avMailitem.Attachments(i)
With grsBLOB
.AddNew
.Fields("CPDID") = vCPDID
.Fields("Attachments") = vAttach
.Update
End With
Next i
End Sub