Code uses a simpler table structure and due to the fact that I didn't bother about reproducing the "autoincrement" field it will get you into troubles if trying to run the sample multiple times.
You'll notice that basically the only different thing is the connection string!
'CREATE CONNECTION OBJECT AND ASSIGN CONNECTION STRING Dim conn As ADODB.Connection Set conn = New ADODB.Connection conn.ConnectionString = "DRIVER={Firebird/Interbase(r) Driver};DBNAME=localhost:C:\Programmi\Firebird\Firebird_2_0\examples\empbuild\test.fdb;UID=SYSDBA;PW D=masterkey" conn.CursorLocation = adUseClient conn.Open 'OPEN RECORDSET FOR WRITING Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset Dim mystream As ADODB.Stream Set mystream = New ADODB.Stream mystream.Type = adTypeBinary rs.Open "SELECT * FROM files WHERE 1=0", conn, adOpenStatic, adLockOptimistic rs.AddNew mystream.Open mystream.LoadFromFile "c:\adaptor.jpg" rs!file_id = 1 rs!file_name = "adaptor.jpg" rs!file_size = mystream.Size rs!file_blob = mystream.Read rs.Update mystream.Close rs.Close 'OPEN RECORDSET TO READ BLOB rs.Open "Select * from files WHERE files.file_id = 1", conn mystream.Open mystream.Write rs!file_blob mystream.SaveToFile "c:\newimage.jpg", adSaveCreateOverWrite mystream.Close rs.Close 'OPEN RECORDSET FOR UPDATE OF BLOB COLUMN rs.Open "Select * from files WHERE files.file_id = 1", conn, adOpenStatic, adLockOptimistic mystream.Open mystream.LoadFromFile "c:\adaptor.jpg" rs!file_blob = mystream.Read rs.Update mystream.Close rs.Close 'OPEN RECORDSET TO READ UPDATED IMAGE rs.Open "Select * from files WHERE files.file_id = 1", conn mystream.Open mystream.Write rs!file_blob mystream.SaveToFile "c:\newupdatedimage.jpg", adSaveCreateOverWrite mystream.Close rs.Close conn.Close MsgBox "Success! Check your C:\ directory for newimage.jpg and newupdatedimage.jpg"
No comments:
Post a Comment