Monday, May 16, 2011

C# & SQLite - Storing Images

Introduction
This article is to demostrate how to load images into a SQLite database and retreve them for viewing. 
It is writen in VS2010, C#, .NET4.0 and uses a ADO.NET provider System.Data.SQLite to connect to the SQLIte database.

And this all in an windows XP environment.

Background

First of all one has to obtain a few files and install them according to the rules.
SQLite Ado.Net provider http://sqlite.phxsoftware.com
SQLite Administrator http://sqliteadmin.orbmu2k.de
Sqlite Administrator http://www.sqlite.org
SQLite ADO.NET provider
I installed the package into my "C:\" directory chose not to register the DLL files,
due to only wanting to include the DLL files to my project.
Using the code
SQLite
First I created a new database named ImageLib.s3db and added a table and required fields.
[ Lib for Libruary ]

CREATE TABLE [ImageStore] (
[ImageStore_Id] INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT,
[ImageFile] NVARCHAR(20)  NULL,
[ImageBlob] BLOB  NULL
);

Read more: Codeproject