Pular para o conteúdo principal

Working With ADO - Saving an Asset Image from Database to File

sConnectionString = 'Provider=MSDASQL.1;Password=masterkey;Persist Security Info=True;User ID=SYSDBA;Data Source=GIDB;'

sConnectionTimeout = 15

sCommandTimeout = 30

Set oApplicationDS = CreateObject('ADODB.Connection')

oApplicationDS.ConnectionTimeout = sConnectionTimeout

oApplicationDS.CommandTimeout = sCommandTimeout

oApplicationDS.Open(sConnectionString)

oSearchSQL = CreateObject('ADODB.Command')

Set oSearchRS = CreateObject('ADODB.Recordset')

oSearchSql.CommandText = 'SELECT GAGES.*,IMAGES.* FROM GAGES LEFT OUTER JOIN IMAGES ON IMAGES.COMPANY=GAGES.EQUIP_IMAGE_COMPANY AND IMAGES.IMAGE_NAME=GAGES.EQUIP_IMAGE WHERE GAGES.COMPANY='ABC COMPANY' AND GAGES.GAGE_SN='BCD101';'

oSearchSql.CommandType = 1

Set oSearchSql.ActiveConnection = oApplicationDS

oSearchRS.Open(oSearchSql)

If not oSearchRS.EOF and not osearchRS.BOF then

MyData = oSearchRS.Fields('SAVED_IMAGE').Value

adTypeBinary = 1

adSaveCreateOverWrite = 2

BinaryStream = CreateObject('ADODB.Stream')

BinaryStream.Type = adTypeBinary

BinaryStream.Open

BinaryStream.Write(MyData)

BinaryStream.SaveToFile('C:\SavedFile.JPG', adSaveCreateOverWrite)

End If

oSearchRS.Close

Set oSearchRS = Nothing

Set oSearchSQL = Nothing

Set oApplicationDS = Nothing |