WPF SQLite ToDo CRUD SQLite


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

In this part we discuss the database. It’s a SQLite database. We need to create a SQLite database file in the same location as our project. We can use DB Browser for SQLite. For this project, if you are following along, create a database called ToDoList.db. For more information on that, please see the post called WPF Installing SQLite and Dapper into Project.

You need to include the database in your project and configure the database. Please follow the above post. You need to configure the two property settings Build Action and Copy to Output Directory.

You will also need to install Dapper. It’s easy to do with NuGet Package Manager. Please refer to the post above for more information.

Below is the connection string. For more information on SQLite connections string you could consult the online reference www.connectionstrings.com/sqlite/.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="Default" connectionString="Data Source=.\ToDoList.db;Version=3;" providerName="System.Data.SqlClient"/>
  </connectionStrings>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
    </startup>
</configuration>

System.Configuration Reference

You need to add a Reference to the System.Configuration. How do you do that? In Visual Studio’s Solution Explorer, right-click “References”, Add Reference… and in the search box type in “config” to more easily locate the System.Configuration. Click the check box to the left of it and click OK.

Error No such table

You might get an error. SQL Logic error. No such table: ToDos. Even thought the error says it can’t find the table, it might be that it can’t find the entire database. If you have the wrong database name in the configuration string and the right table name, you will get the error that says no such table. If you put a bad table name in your select query you will also get the same error. Often times the error messages you get are not as specific as you’d like.

Series Navigation<< WPF SQLite ToDo CRUD XAMLWPF SQLite ToDo CRUD Code >>