Click here to Skip to main content
13,556,574 members
Click here to Skip to main content
Add your own
alternative version


57 bookmarked
Posted 16 Aug 2007

Simple C# Wrapper for SQLite

, 16 Aug 2007
Rate this:
Please Sign up or sign in to vote.
An article that describes lightweight C# wrapper for SQLite


This article describes a very simple wrapper class for SQLite. This class provides only few simple functions: opening and closing database, returning the list of tables and executing queries. Although these are basic functions, they are enough for someone who needs only a storage engine for his/her program.


While writing this class, I've been using ADO.NET Data Provider for SQLite as a reference, which I found here.

Using the Code

Using this class is very easy: add a reference to this DLL (Project->AddReference...) in your project and a line to your code:

using SQLWrapper;

Now you can start using database functions in your program.


// creates a new instance of SQLiteBase and opens database in file "test.db"
SQLiteBase db = new SQLiteBase("test.db");
// executes SELECT query and store results in new data table
DataTable table = db.ExecuteQuery("SELECT * FROM table1 WHERE id = 1;");
// closes the database

Source Code

There are two constructors and and five public functions:

  • OpenDatabase
  • CloseDatabase
  • GetTables
  • ExecuteNonQuery
  • ExecuteQuery

which are all well-documented in the source file, so I don't see a point in explaining them again.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer (Junior)
Croatia Croatia
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionPerfomance? Pin
Member 1157682716-Jan-16 9:10
memberMember 1157682716-Jan-16 9:10 
QuestionUpdates for .NET 4.5.1 ? Pin
kiquenet.com31-Jan-14 4:06
memberkiquenet.com31-Jan-14 4:06 
QuestionProblem Pin
daghune19-Oct-13 0:29
memberdaghune19-Oct-13 0:29 
GeneralThanks Pin
nikzorom9-Jan-13 10:32
membernikzorom9-Jan-13 10:32 
QuestionOpen database with password Pin
moez.hielmy27-Aug-12 17:06
membermoez.hielmy27-Aug-12 17:06 
GeneralEtrow Exception Pin
Al Baikr16-Jul-10 21:30
memberAl Baikr16-Jul-10 21:30 
Rant[My vote of 2] Not reacting to malformed queries Pin
Robhol5-Jul-10 12:44
memberRobhol5-Jul-10 12:44 
GeneralUpdate for Net 4.0 [modified] Pin
anss1236-Jun-10 21:04
memberanss1236-Jun-10 21:04 
GeneralRe: Update for Net 4.0 Pin
upsfeup7-Jul-10 4:24
memberupsfeup7-Jul-10 4:24 
GeneralRe: Update for Net 4.0 Pin
anss12327-Aug-10 3:59
memberanss12327-Aug-10 3:59 
GeneralHaving Error: library routine called out of sequence Pin
upsfeup26-May-10 2:44
memberupsfeup26-May-10 2:44 
GeneralRe: Having Error: library routine called out of sequence Pin
anss1234-Jun-10 3:02
memberanss1234-Jun-10 3:02 
Try inserting this snipped of code before "return sqlite3_step(statement);" in the "ReadFirstRow" function:

        if (resultType != 101 && resultType != 0)
          throw new Exception("There was an error of type: "+resultType+" - See");

Then execute the Insert statements using "ExecuteQuery", not "ExecuteNonQuery". Look up the error code and you should have a better idea of what's going on.
GeneralMy Sincerest THANKS!! Pin
kidzopa15-May-10 16:12
memberkidzopa15-May-10 16:12 
GeneralA possible alternative; NFileStorage Pin
snip117-Mar-09 6:54
membersnip117-Mar-09 6:54 
Generalcreate a database Pin
Chaozzster16-Feb-09 6:28
memberChaozzster16-Feb-09 6:28 
GeneralRe: create a database Pin
thk_sompi1-Mar-09 12:16
memberthk_sompi1-Mar-09 12:16 
GeneralRe: create a database Pin
Ken Eucker3-Jun-09 9:25
memberKen Eucker3-Jun-09 9:25 
GeneralRe: create a database Pin
fbelic3-Jun-09 23:14
memberfbelic3-Jun-09 23:14 
GeneralRe: create a database Pin
Ken Eucker4-Jun-09 21:19
memberKen Eucker4-Jun-09 21:19 
Generalout of memory Pin
saifsail24-Jan-09 8:32
membersaifsail24-Jan-09 8:32 
GeneralPossible memory leak Pin
Jacky__E24-Nov-08 3:34
memberJacky__E24-Nov-08 3:34 
GeneralRe: Possible memory leak [modified] Pin
oren.shnitzer22-Dec-08 10:21
memberoren.shnitzer22-Dec-08 10:21 
GeneralRe: Possible memory leak Pin
Jacky__E23-Dec-08 3:16
memberJacky__E23-Dec-08 3:16 
GeneralNo more memory leak Pin
Sten Hjelmqvist23-Sep-09 2:19
memberSten Hjelmqvist23-Sep-09 2:19 
GeneralRe: Possible memory leak Pin
kidzopa15-May-10 16:28
memberkidzopa15-May-10 16:28 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180515.1 | Last Updated 16 Aug 2007
Article Copyright 2007 by fbelic
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid