"Stephanie Stowe" <IwishIcould RemoveThis @nospam.com> wrote in message
news:%23oVINt5EFHA.2756@TK2MSFTNGP15.phx.gbl...
>I have a problem related to a field in a SQL table whcih is an "image"
>datatype. The powers that be here claim it is a bmp. I think it is not, or
>that it is encrypted in some way. I would like to test my theory by reading
>the data in the field and writing it to disk. Then I want to open my bmp
>and see if I can see it. I have never done anything with blobs or anything
>other than standard, non binary data. Does anyone have a little sample of
>reading this kind of data out of a table. I have seen the GetChunk method
>but I do not see how to write this to the file system. If you can point me
>in the direction of the best file system object(s) instead.... I think I
>just need a nudge. Thanks.
First off, you're over-thinking the "image" thing, it's just a name, no
transformations are performed. If you save Word Document data into an image
file, you'll get Word Doc back out. (You'd probably want to convert bmp's
to jpg's before storing them, but that's beside the point -- SQL won't do
that for you.)
And here's your nudge.
Good Luck,
Mark
Dim FileName As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
'''''
' assume recordset is opened and positioned, that the first
' column of the recordset is of type image, and the string
' FileName has been assigned with a valid, fully-qualified
' file name.
'
''''''
Dim oStr As ADODB.Stream
Set oStr = New ADODB.Stream
oStr.Mode = adModeReadWrite
oStr.Type = adTypeBinary
oStr.Open
' load binary contents of a file into stream
'
oStr.LoadFromFile FileName
oStr.Position = 0
' create a record and write the file to blob field by reading it
' from the stream
'
rs.AddNew
rs.Fields(0).Value = oStr.Read()
rs.Update
''''''''''''''''''
' or read the blob from the db and save it to file
'
oStr.Write rs.Fields(0).Value
oStr.Position = 0
oStr.SaveToFile FileName, adSaveCreateNotExist<!-- ~MESSAGE_AFTER~ -->