I'm trying to incorporate the following code into my existing code.
Here is my test code that works:
Sub test()
Dim con As ADODB.Connection
Dim rs As ADODB.recordSet
Set con = New ADODB.Connection
Set rs = New ADODB.recordSet
con.Open "Provider=SQLOLEDB;Password=;User ID=;Initial
Catalog='" & Worksheets("Settings").Range("C2").Value & _
"';Data Source='" & Worksheets("Settings").Range("A2").Value & "';"
'Open database connection
rs.ActiveConnection = con
rs.Open "select * from QuoteData", con, adOpenKeyset,
adLockOptimistic
Set mstream = New ADODB.Stream
mstream.Type = adTypeBinary
mstream.Open
mstream.LoadFromFile "c:\temp\pictures\pic1.jpg"
rs.Fields("PII_Image1").Value = mstream.Read
rs.Update
End Sub
This is the code I'm using in my existing code. UpdateQuery is part of a larger string. I want to integrate it with my existing update query.
Set mstream = New ADODB.Stream
mstream.Type = adTypeBinary
mstream.Open
mstream.LoadFromFile "c:\temp\pictures\pic1.jpg"
updateQuery = updateQuery & "PII_Image1=convert(varbinary(MAX),'mstream.Read'),"
mstream.Close
This code runs, but it only inserts something into the database that looks like '0x6D73747265616D2E52656164' which isn't correct. I'm trying to figure out why. If I take away the convert piece, it says it can't convert varchar to varbinary(MAX).
'quote? Looking at the lines above it, I think there's an issue with that part of code. Also, what are you expecting to be added to the database? A file?