As you have heard repeatedly, storage of such files in the database is not
recommended; however, if you still want to know how it's done, here's an
exaple using an image file:
To save an existing image file to the database:
Substitute the "c:\ImagePath\MyImage.gif" with
the name of the image file you want to save.
This assumes the existence of the recordset "oRs"
which contains the field "ImgField"
'--------------------------
Dim mStream As ADODB.Stream
Set mStream = New Stream
With mStream
.Type = adTypeBinary
.Open
.LoadFromFile "c:\ImagePath\MyImage.gif"
End With
oRs.Add
oRs("ImgField").value = mStream.Read
'-----------------------------------
To show the image, you need to extract the field containing the
image to a (temporary) file and do a "LoadPicture" on the file.
Let's assume you have a recordset "oRs" which contains the field
"ImgField" and a PictureBox called "Picture1" on your form:
'-----------------------------------
Dim sFile As String
sFile = App.Path & "\image.tmp"
Dim mStream As ADODB.Stream
Set mStream = New Stream
With mStream
.Type = adTypeBinary
.Open
.Write oRs("ImgField").Value
.SaveToFile sFile, adSaveCreateOverWrite
End With
Set Picture1.Picture = LoadPicture(sFile)
'-----------------------------------
Regards,
-Toby
>From: "Niall Hannon (ext. 772)" <Niall.Hannon@f...>
>Date: Wed, 15 Jan 2003 16:12:39 -0000
>
>Hi,
>
>Is it possible to save .avi, .mpeg2 etc files in MS Acess or SQL Server? Is
>it possible to store the complete file in a field of a table (using OLE
>Object?) and then later play it from a vb app etc?
>
>
>Thanks
>Niall