|
-
Apr 20th, 2001, 05:42 PM
#1
Thread Starter
New Member
How can I save and retrieve WAVE files from/to an Access database using only VB Code?
I can do it with the OLE container and ADO/DAO controls but how about without using any OLE container?
Your help is really appreciated!
[email protected] (Jelatinas)
-
Apr 20th, 2001, 06:52 PM
#2
You probably can't unless you wanted to save the ENTIRE wave file as a string. If you want to know how to do that, look around the forums, because I'm not sure how.
Z.
-
Apr 21st, 2001, 04:54 AM
#3
Fanatic Member
I know how to do it using DAO, but it should be similar using ADO. In your database, create a field called something like WaveData, with the dbLongBinary type (or OLE_OBJECT as it's called in Access I think). Then you can just read and write the WAV file like this: (DAO sample)
Code:
Dim WS As DAO.Workspace
Dim DB As DAO.Database
Dim RS As DAO.Recordset
Dim bData() As Byte
Dim iFree As Integer
' Open the database, And the 'Waves' table...
Set WS = DBEngine.Workspaces(0)
Set DB = WS.OpenDatabase("c:\wav.mdb")
Set RS = DB.OpenRecordset("Waves")
' Read the WAV file
iFree = FreeFile()
Open "c:\sample.wav" For Binary Access Read As #iFree
ReDim bData(LOF(iFree))
Get #iFree, , bData()
Close #iFree
' Add it To the database
RS.AddNew
RS("WaveData") = bData()
RS.Update
' Now To read it again, move To the first item (To keep it simple)
RS.MoveFirst
' Size the Byte array And read it from the DB
ReDim bData(RS("WaveData").FieldSize)
bData() = RS("WaveData")
' Now you can Write it To a file again, like this:
iFree = FreeFile()
Open "c:\fromdb.wav" For Binary Access Write Lock Read Write As #iFree
Put #iFree, , bData()
Close #iFree
' Close the DB
Set RS = Nothing
Set DB = Nothing
Set WS = Nothing
Hope this helps...
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
-
Apr 23rd, 2001, 01:56 PM
#4
Thread Starter
New Member
It works!!!!!!
Thank you very much PsychoMark!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|