SQLite create database for Windows WPF Desktop

8.2k views Asked by At

I have a WPF Desktop application which I want to connect to a SQLite database. I've read this tutorial about sqlite-net. I've installed it using NuGet.

When I start my application I want to check if the db file exists and if not create it, but sqlite-net doesn't have a CreateDatabase option. It looks like it assumes the file is pre-created.

I've also installed System.Data.SQLite (x86/x64) using NuGet, but I still can't find a method to create a database through C# code.

Can anybody give me some pointers so I can continue?

Thanks.

1

There are 1 answers

2
Markus Palme On BEST ANSWER

sqlite-net creates the database file for you when you call the CreateTable method (and it doesn't already exist). Take a look at the getting started guide for a full example:

var db = new SQLiteConnection("mydatabase.db");
db.CreateTable<Person>();