Click here to Skip to main content
15,892,537 members
Articles / Programming Languages / SQL

C# & SQLite – Storing Images

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
16 Sep 2011CPOL1 min read 20.4K   10   2
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 ].

SQL
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.

This article was originally posted at http://blog.kribo.be/blog?p=125

License

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


Written By
Web Developer
Belgium Belgium
Developer within C#, Dynamics NAV (Navision), Php environments.

Comments and Discussions

 
QuestionThe images are referenced or is a real store in the database? Pin
innuendoreplay5-Oct-11 18:28
innuendoreplay5-Oct-11 18:28 
AnswerRe: The images are referenced or is a real store in the database? Pin
kribo6-Oct-11 5:51
professionalkribo6-Oct-11 5:51 

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

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