Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

C# & SQLite – Storing Images

, 16 Sep 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

kribo
Software Developer
Belgium Belgium
Developer within C#, Dynamics NAV (Navision), Php environments.
Follow on   Twitter   LinkedIn

Comments and Discussions

 
QuestionThe images are referenced or is a real store in the database? Pinmemberinnuendoreplay5-Oct-11 19:28 
AnswerRe: The images are referenced or is a real store in the database? Pinmemberkribo6-Oct-11 6:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 16 Sep 2011
Article Copyright 2011 by kribo
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid