65.9K
CodeProject is changing. Read more.
Home

C# & SQLite – Storing Images

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Sep 16, 2011

CPOL

1 min read

viewsIcon

20691

This post aims to demostrate how to load images into a SQLite database and retrieve them for viewing.

This post aims to demonstrate how to load images into a SQLite database and retrieve them for viewing.

It is written in VS2010, C#, .NET4.0 and uses a ADO.NET provider System.Data.SQLite to connect to the SQLIte database.

And this all in a Windows XP environment.

First of all, one has to obtain a few files and install them according to the rules.

SQLite ADO.NET provider

I installed the package into my “C:\” directory and chose not to register the DLL files, due to only wanting to include the DLL files to my project.

SQLite

First I created a new database named ImageLib.s3db and added a table and required fields.
[ Lib for Library ].

CREATE TABLE [ImageStore] (
[ImageStore_Id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[ImageFile] NVARCHAR(20) NULL,
[ImageBlob] BLOB NULL
);
VS2010 – C# – .NET 4.0

Next I created a VS2010 project named StoringImages, changed the default namespace and added a few folders and files.

  • folder: Database
    • file: StoringImages.s3db
      • Property: Copy to Output Directory => Copy Always
  • folder: Model
    • dBFunctions.cs
    • dBHelper.cs
    • Image.cs
    • ImageHelper.cs
  • file: System.Data.SQLite.dll
    • Property: Copy to Output Directory => Copy Always
  • file: SQLite.Interop.dll
    • Property: Copy to Output Directory => Copy Always
  • form: DisplayImages
    • This is the startup form of the project

Both System.Data.SQLite.dll and SQLite.Interop.dll need to be placed just beneath the root (project) StoringImages.

This ensures that both files are installed into the same directory as the projects “*.exe” file.

You can download the source code here.

For the rest of the article and more details, please visit CodeProject.com.