How to manipulate media files "BLOBs" using Visual Basic with a Database end.
What is BLOB?
BLOB is Binary Large Objects, any multimedia object within Win OS is called BLOB, not all Databases support BLOBs. the term BLOB was originally used to call the process of moving large amounts of Data from a Database to another Database without any errors.
How does it work?
Saving BLOBs into a Database is easy as storing anything else. There are 3 famous methods to store files into a Database, these methods are :
- Binary
- File Pointer
- BLOB
We will create a Visual Basic 6.0 project to only store files like Images into Microsoft Access Database 2003 (*.mdb) and retrieve these BLOBS again into the Visual Basic 6.0 Project. We will use ADO 2.8 technology to work with the Database. Storing photos into a Database is the same thing as storing Audio files, Pdf files, Videio files, .... etc.
How to use GetChunk() and AppendChunk() ?
The GetChunk and AppendChunk methods work with the LongVarChar, LongVarWChar, and LongVarBinary column types, also known as TEXT, NTEXT, and IMAGE columns, in Microsoft SQL Server, and as MEMO and OLE fields in Microsoft Jet databases. You can identify these columns in ADO by testing the Type property of a Field for the values adLongVarChar, adLongVarWChar, and adLongVarBinary. You can also test the Attributes property of a Field for the adFldLong flag.
Long columns are commonly referred to as BLOBs (Binary Large OBjects) even though they may contain text data. The sample code below provides two routines, BlobToFile and FileToBlob.
What is the project example about
Our Visual Basic 6.0 project example is about creating a friends directory of our friends. We will store Data like [first name, last name & Avatar], the project will contain one form designed like this :
As you can see the design is so simple and a source code *.Vbp will be included in the end of the page. It goes like this :
- Fill in the First Name field, Last Name field and pic a photo from your computer
- Choose a method to save [Binary, File Pointer or BLOB]
- Click on Save
- Navigate through your Data stored into the Database *.mdb
- Notice the result on the form.
Source Code Highlights
OurGeneral Declaration area contains Variables to connect to the Database file MyBase.mdb and Variables to read the Image file :
Another block of code to read the Image file :
Another block of code to retrieve the Image file:
Downloan the source code from a direct link from Mediafire.com