如何获取文件(映像)路径位置并将其插入SQL语句到MSSQL?

时间:2017-07-03 10:58:27

标签: sql-server vba excel-vba excel

我试图在我的MSSQL数据库中插入图像,并根据用户使用变量" strpath"选择的路径渲染图像。我不知道是否可能,但我仍然得到一个错误。有人可以帮忙吗?

Private Sub Cmdbutton_selectimage_Click()

Dim strpath As String
Dim cou As Integer

Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
cou = Application.FileDialog(msoFileDialogOpen).Show

If cou <> 0 Then
    strpath = Application.FileDialog(msoFileDialogOpen).SelectedItems(1)
    Image1.Picture = LoadPicture(strpath)
    Image1.PictureSizeMode = 1


End If
End Sub


Function GetInsertImage() As String

Dim SQLStrImage As String

SQLStrImage = _
    "INSERT INTO PeopleImage(Image)" & _
    " SELECT BulkColumn" & _
    " FROM Openrowset(Bulk '" & strpath & "', Single_Blob) as image"

GetInsertImage = SQLStrImage

End Function

我尝试插入并手动定义路径位置,例如C:\ Users \ XYZ \ Desktop \ images.png&#39;它完美地工作(插入表PeopleImage作为二进制) - 这完美地工作

Function GetInsertImage() As String

Dim SQLStrImage As String

SQLStrImage = _
    "INSERT INTO PeopleImage(Image)" & _
    " SELECT BulkColumn" & _
    " FROM Openrowset(Bulk 'C:\Users\XYZ\Desktop\images.png', Single_Blob) as image"

GetInsertImage = SQLStrImage

End Function

0 个答案:

没有答案