Microsoft Visual Basic training - Saving/retrieving Media Files into/from Database

How to work with media file in Visual Basic with a Database


vby6 home

BLOBs vb6

How to manipulate media files "BLOBs" using Visual Basic with a Database end.

Introduction

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.

Logic

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 :

  1. Binary
  2. File Pointer
  3. 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.

Using GetChunk()

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.

Project Design

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 :

vb6 mdb files saving

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 :

Source Code

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

About Us | Contact Us | ©2013 evry1falls


Free Web Hosting