Function AddImage(ByVal FileName As String) As String
Dim rs As ADODB.Recordset
Dim conn As ADODB.Connection
Dim stm As ADODB.Stream
Dim result As Integer
Set rs = New ADODB.Recordset
Set conn = New ADODB.Connection
With conn
.ConnectionString = MASTER_ODBC_CONNECTION_STRING
.Open
With rs
.Open "SELECT * FROM PictureTest WHERE 1 = 0", conn, adOpenDynamic, adLockOptimistic
Set stm = New ADODB.Stream
stm.Type = adTypeBinary
stm.Open
stm.LoadFromFile FileName
' Insert the binary object into the table.
.AddNew
.Fields("PictureData").value = stm.Read
.Update
result = .Fields("ID").value
stm.Close
Set stm = Nothing
.Close
End With
Set rs = Nothing
.Close
End With
Set conn = Nothing
End Function
|