Daily Thought Program in WPF, SQLite and Dapper


This entry is part 1 of 7 in the series WPF Daily Thought

This series of posts illustrates how to code a Windows program that displays a quote or thought for the day, along with an explanation for each thought. Feel free to build this yourself and copy any of these listings in the following series of posts. When you start the program, the system date is read from the Windows computer and the thought for that day is displayed, along with an explanation of that thought. The user can use the forward and back buttons to go to tomorrow’s thought or yesterdays’ thought. The user can continue to move forward and back through the days by clicking the forward and back buttons.

The thoughts themselves are stored in a SQLite database, which is local to the computer and not connected to the Internet or to any other central database or databases. We use the ORM Dapper to make it easier to work with SQLite. SQLite is a great choice for storing data that only needs to exist on the local machine. The developer/coder of the program is responsible for entering the different thoughts and comments into the database.

The interface is simple, as shown in the wireframe on the left that I made with the software called Figma. The database contains the date, the thought and the comment that’s shown under the thought. Also, the database contains an Id column that is the primary key. It starts at 1 and increments by 1 each time.

The focus of this demo is connecting to and reading data from a SQLite database and displaying it on an interface. We don’t write to or delete from the database in this program. The program uses SQL to get a single row (record) from the database and store it in a C# class to be then displayed in elements that we’ve named in our XAML code. Secondarily this demo will illustrate the challenge we sometimes have with dates and date formatting. SQLite does not have a date format in their database, but C# does have a DateTime type we can use. This demo program also illustrates a bit of XAML, especially the StackPanel, Button, Polygon and DatePicker. Finally, this program illustrates C# code and deployment of your WPF Windows program.

Series NavigationDaily Thought WPF Front-End >>