Member-only story
How to Insert & Select data using SQLite in a C# console application
In this tutorial I will show you how to use SQLite in a C# console application.
For this tutorial I will be using Rider (which at the moment is my favourite IDE) to create a C# console application.
After you have created the project you will be greeted with a “Program.cs” file. Now create a class file named “DatabaseConfig” in the root of the project . This file will contain code that configures and creates our sqlite file.
The next step is to download a nuget package named “System.Data.Sqlite”
Once you have done this navigate to the “DatabaseConfig” file and add the “System.Data.Sqlite” package to the top of the page as well as the “System” and “System.IO” namespace.
In addition, within the “DatabaseConfig” class create a variable which is equal to type “SQLiteConnection”. We will use this to set the data source which will be an sqlite file and the data sources filename.
public SQLiteConnection mySQLiteConnection;
Now we need to create a constructor where we set the above variable equal to a value and use the…