Click here to Skip to main content
Licence 
First Posted 16 Aug 2007
Views 71,203
Downloads 1,607
Bookmarked 51 times

Simple C# Wrapper for SQLite

By fbelic | 16 Aug 2007
An article that describes lightweight C# wrapper for SQLite
4 votes, 25.0%
1
1 vote, 6.3%
2

3
4 votes, 25.0%
4
7 votes, 43.8%
5
3.19/5 - 16 votes
μ 3.19, σa 3.00 [?]

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:

using SQLWrapper;

Now you can start using database functions in your program.

Example:

// 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

About the Author

fbelic

Software Developer (Junior)

Croatia Croatia

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralEtrow Exception PinmemberAl Baikr22:30 16 Jul '10  
Rant[My vote of 2] Not reacting to malformed queries PinmemberRobhol13:44 5 Jul '10  
GeneralUpdate for Net 4.0 [modified] Pinmemberanss12322:04 6 Jun '10  
GeneralRe: Update for Net 4.0 Pinmemberupsfeup5:24 7 Jul '10  
GeneralRe: Update for Net 4.0 Pinmemberanss1234:59 27 Aug '10  
GeneralHaving Error: library routine called out of sequence Pinmemberupsfeup3:44 26 May '10  
GeneralRe: Having Error: library routine called out of sequence Pinmemberanss1234:02 4 Jun '10  
GeneralMy Sincerest THANKS!! Pinmemberkidzopa17:12 15 May '10  
GeneralA possible alternative; NFileStorage Pinmembersnip17:54 17 Mar '09  
Generalcreate a database PinmemberChaozzster7:28 16 Feb '09  
GeneralRe: create a database Pinmemberthk_sompi13:16 1 Mar '09  
GeneralRe: create a database PinmemberKen Eucker10:25 3 Jun '09  
GeneralRe: create a database Pinmemberfbelic0:14 4 Jun '09  
GeneralRe: create a database PinmemberKen Eucker22:19 4 Jun '09  
"Cannot create instance of 'Window1' defined in assembly 'sqlSample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'Window1.xaml' Line 1 Position 9."
 
In debugging the error, it happens when I try to open a database (the file does not currently exist). But it should make the db file if it doesn't exist correct?
 
I am not entirely sure that I am implementing this correctly. From a blank solution all I have to do is insert the dll you provided into the project as a reference and I can start making/using sqlite?
Generalout of memory Pinmembersaifsail9:32 24 Jan '09  
GeneralPossible memory leak PinmemberJacky__E4:34 24 Nov '08  
GeneralRe: Possible memory leak [modified] Pinmemberoren.shnitzer11:21 22 Dec '08  
GeneralRe: Possible memory leak PinmemberJacky__E4:16 23 Dec '08  
GeneralNo more memory leak PinmemberSten Hjelmqvist3:19 23 Sep '09  
GeneralRe: Possible memory leak Pinmemberkidzopa17:28 15 May '10  
GeneralSame Error PinmemberMember 33120559:50 21 Sep '08  
GeneralRe: Same Error PinmemberMember 331205510:21 21 Sep '08  
Generalfacing some bug with your dll Pinmemberchal_adiera23:42 27 Aug '08  
QuestionCan I use it in my Media Player? PinmemberSukhjinder_K1:58 4 Jan '08  
GeneralVery Nice & Easy to Use PinmemberSukhjinder_K22:22 15 Nov '07  

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.

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