First of all we need to add SQLite support to our application. There are two ways of doing that
We’ll do it the second way
First open the NuGet menu
and search for System.Data.SQLite, select it and hit Install
Installation can also be done from Package Manager Console with
PM> Install-Package System.Data.SQLite
Or for only core features
PM> Install-Package System.Data.SQLite.Core
That’s it for the download, so we can go right into coding.
First create a simple SQLite database with this table and add it as a file to the project
CREATE TABLE User(
Id INTEGER PRIMARY KEY AUTOINCREMENT,
FirstName TEXT NOT NULL,
LastName TEXT NOT NULL
);
Also do not forget to set the Copy to Output Directory property of the file to Copy if newer of Copy always, based on your needs
Create a class called User, which will be the base entity for our database
private class User
{
public string FirstName { get; set; }
public string Lastname { get; set; }
}
We’ll write two methods for query execution, first one for inserting, updating or removing from database