【发布时间】:2017-03-25 10:19:56
【问题描述】:
我想将 word 文档的所有图像存储在 sql 数据库中。我发现了几个关于如何通过InlineShapes 集合解析图像的代码示例,它们工作正常。但是,我现在缺少一个关于如何将图像存储在 sql server 图像列中的示例。
任何人都可以发布一个示例,它将InlineShape 对象存储在数据库中。使用command 或recordset 对象?
更新:这是代码
Sub SavePictures()
Dim SQL As String
Dim RS As ADODB.Recordset
Dim cnBon As ADODB.Connection
Dim intCount As Integer
Dim i As Integer
SQL = "Select [ID] ,[Datei] ,[Seite] ,[Bild] from Bilder Where 1=0"
strConn = "working Connection string"
Set cnBon = New ADODB.Connection
cnBon.Open strConn
Set RS = CreateObject("ADODB.Recordset")
RS.Open SQL, cnBon, adOpenKeyset, adLockOptimistic, adCmdText
For i = 1 To InlineShapes.Count
If InlineShapes.Item(i).Type = wdInlineShapePicture Then
RS.AddNew
RS("Datei") = ActiveDocument.Name
RS("Seite") = i
'This is where I'm stuck. How do I Access the Picture to save it in the Recordset?
RS("Bild") = InlineShapes.Item(i)
RS.Update
End If
Next i
RS.Close
cnBon.Close
Set RS = Nothing
Set cbbon = Nothing
End Sub
【问题讨论】:
标签: sql-server vba sql-server-2012 ms-word