WPF SQLite ToDo CRUD Introduction


This entry is part 1 of 6 in the series WPF SQLite ToDo CRUD

This post is the first of a short series of posts about creating a WPF project that allows a user to create a very simple Windows to-do list program, and manage that list. The list of our website posts is shown on the right. The data is persistent, meaning that it will be stored in a database and stored on the disk so that each time we run the program the previous changes made are retained. We will use the database SQLite and get help with the storage from Dapper. We will demonstrate CRUD (Create, Read, Update, and Delete) in this project. This is just meant for demonstration and learning purposes. It illustrates the basics of connecting a WPF project to a SQLite database that provides CRUD.

Here is a list, roughly in order, of the things we need to work on to get this done.

  1. XAML MainWindow.xaml
  2. Data Model: ToDo.cs class creation
  3. SQLite Database installation, creation and configuration
  4. Dapper installation
  5. App.config connection strings
  6. System.Configuration Reference addition
  7. C# code behind MainWindow.xaml.cs
  8. SQLiteDataAccess.cs class creation

Intentionally Simple

This project is set up to be as simple as possible, yet still have CRUD functionality. CRUD stands for Create, Read, Update and Delete. The ToDo model only has Name and Status, plus an Id that is an autoincrementing primary key. In a real project you would likely have more properties in the model, but these could be added later. You would likely also have a drop-down that allows the use to pick from a list of Status possibilities. You might also have dates that keep track of when the status changed. You might also have a property that keeps track of who (which user) made the change. You would also need a description property so that details could be added, and so on. We do not have very good validation in this project. To add a new todo, the user needs to add text in both boxes, but the number of characters they can type is not limited. It should be.

The three most interesting and difficult parts of the project are parts 1, 7, and 8. The most important part to get right is the data model in part 2. The data model in part 2 flows down and affects parts 1, 3, 4, 7, and 8 if you make any changes to part 2.

After the user adds a new todo, the two text boxes clear but the new todo is not displayed in the list until the user clicks the Refresh List button. Also, after the user edits a todo, the changes are not displayed until the user clicks the Refresh List button.

Source Code

The final source code will be given in a short series of posts. This series of posts is not a tutorial. I’m just posting the code with a bit of explanation. I’m not giving a full instructional lesson on how to build this and how it works.

However, I like Tim Corey’s YouTube tutorial called Using SQLite in C# – Building Simple, Powerful, Portable Databases for Your Application. This series of posts is based on that video, but he uses a different example, People, covers adding and displaying records, and uses WinForms not WPF.

Series NavigationWPF SQLite ToDo CRUD XAML >>