Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#3.5

C# & SQLite – System.Data.SQLite 1007000

0.00/5 (No votes)
16 Sep 2011CPOL2 min read 15.1K  
C# & SQLite – System.Data.SQLite 1007000
  • Building a VS2010 project using an SQLite embedded database
  • Project codename "Contact"
  • I’ll be demonstrating how to insert, edit and delete records from the database

First of all, you’ll have to acquire a few files and install a few necessary software packets.

SQLite Admin Tool

For this tool, I chose the full install and I’m pleased with the result.

SQLite ADO.Net Provider

This tool I installed in a C:\Temp file and I chose not to register the DLL files. This is because I just needed to include the main DLL in my project.

First, we create a SQLite dB named "Contact.3db" using the SQLite Admin tool. I added a table "Contact" with a few fields and inserted a few records of data to play with.

SQL
CREATE TABLE [Contact] (
[contact_id] INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL,
[FirstName] vARCHAR(50)  NULL,
[LastName] vARCHAR(50)  NULL)

Next I created a VS2010 project named "Contact" and added a few folders and files:

  • Add a folder[Database] and insert an existing Item "Contact.3db"
  • Change the property "Copy to Output Directory" -> "Copy Always"

Next, I added the essential SQLite DLL to my project.
System.Data.SQLite.dll -> change the property "Copy to Output Directory" -> "Copy Always"
SQLite.Interop.dll -> change the property "Copy to Output Directory" -> "Copy Always"

Remark: Both files [System.Data.SQLite.dllSQLite.Interop.dll] must be included just under the root project "Contact".
Contact
-> System.Data.SQLite.dll ->  SQLite.Interop.dll

Next, I added a folder named "Classes" and created two classes to handle all dB transactions:dBFunctions.cs and dBHelper.cs.

Next, I added a folder named "Forms" and created a few forms to handle Interaction / Interface
ContactList.cs, BaseContact.cs, NewContact.cs, EditContact.cs, DeleteContact.cs.

And this includes my files within my project.

You can download the source code here.

For a more details, show and tell [screenshots & code samples], you can read this article on CodeProject.

License

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