Click here to Skip to main content
15,867,568 members
Articles / Programming Languages / C#
Article

Simple C# Wrapper for SQLite

Rate me:
Please Sign up or sign in to vote.
3.25/5 (20 votes)
16 Aug 2007 152.3K   6.1K   58   32
An article that describes lightweight C# wrapper for SQLite

Introduction

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.

Background

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:

C#
using SQLWrapper;

Now you can start using database functions in your program.

Example:

C#
// 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
db.CloseDatabase();

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.

License

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


Written By
Software Developer (Junior)
Croatia Croatia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralHaving Error: library routine called out of sequence Pin
upsfeup26-May-10 2:44
upsfeup26-May-10 2:44 
GeneralRe: Having Error: library routine called out of sequence Pin
anss1234-Jun-10 3:02
anss1234-Jun-10 3:02 
GeneralMy Sincerest THANKS!! Pin
SurlyCanuck15-May-10 16:12
professionalSurlyCanuck15-May-10 16:12 
GeneralA possible alternative; NFileStorage Pin
snip117-Mar-09 6:54
snip117-Mar-09 6:54 
Generalcreate a database Pin
Chaozzster16-Feb-09 6:28
Chaozzster16-Feb-09 6:28 
GeneralRe: create a database Pin
thk_sompi1-Mar-09 12:16
thk_sompi1-Mar-09 12:16 
GeneralRe: create a database Pin
Ken Eucker3-Jun-09 9:25
Ken Eucker3-Jun-09 9:25 
GeneralRe: create a database Pin
fbelic3-Jun-09 23:14
fbelic3-Jun-09 23:14 
GeneralRe: create a database Pin
Ken Eucker4-Jun-09 21:19
Ken Eucker4-Jun-09 21:19 
Generalout of memory Pin
saifsail24-Jan-09 8:32
saifsail24-Jan-09 8:32 
GeneralPossible memory leak Pin
Jacky__E24-Nov-08 3:34
Jacky__E24-Nov-08 3:34 
GeneralRe: Possible memory leak [modified] Pin
oren.shnitzer22-Dec-08 10:21
oren.shnitzer22-Dec-08 10:21 
GeneralRe: Possible memory leak Pin
Jacky__E23-Dec-08 3:16
Jacky__E23-Dec-08 3:16 
GeneralNo more memory leak Pin
Sten Hjelmqvist23-Sep-09 2:19
Sten Hjelmqvist23-Sep-09 2:19 
GeneralRe: Possible memory leak Pin
SurlyCanuck15-May-10 16:28
professionalSurlyCanuck15-May-10 16:28 
GeneralSame Error Pin
Member 331205521-Sep-08 8:50
Member 331205521-Sep-08 8:50 
GeneralRe: Same Error Pin
Member 331205521-Sep-08 9:21
Member 331205521-Sep-08 9:21 
Generalfacing some bug with your dll Pin
chal_adiera27-Aug-08 22:42
chal_adiera27-Aug-08 22:42 
QuestionCan I use it in my Media Player? Pin
Sukhjinder_K4-Jan-08 0:58
Sukhjinder_K4-Jan-08 0:58 
GeneralVery Nice & Easy to Use Pin
Sukhjinder_K15-Nov-07 21:22
Sukhjinder_K15-Nov-07 21:22 
AnswerRe: Very Nice & Easy to Use Pin
Jacky__E23-Dec-08 3:18
Jacky__E23-Dec-08 3:18 
GeneralThanks for this class Pin
flangset29-Aug-07 0:02
flangset29-Aug-07 0:02 

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.