:::: MENU ::::

Using SQLite in WPF Application

As you know SQLite is light weight database no need of any set up configuration and easy to use. If you already used SQLite with windows/Phone apps then you are almost there. For this post I assume that you had already worked with SQLite if not at least with SQL server for your application. There is no any complex steps to follow for doing this in WPF. It’s almost same like what you did before. Here is step by step guide for using SQLite in WPF application.

  1. Install SQLite package from Nuget in your project. This package works with both 32/64 bit version of your machine.
  2. Once it’s installed start with making connection string and write some query with SQLite.
  3. Connection string looks like this. Add System.Data.SQLite namespace.

Remember that you have to provide database name as data source like shown in connection string i.e. “Data Source=Student.db”. You can see your created database in Debug folder of your application and with any SQLite browser application you can view it, can do query on it, make changes on it etc. etc.

Now here is basic CRUD operations in SQLite database.

As you can see there is no new concept for using SQLite in WPF. You can see the connection string like of SQL with even less configuration(only passing database name as data source), Class and Methods like SQLiteDataReader, SQLiteCommand, ExecuteNonQuery, ExecuteDataReader all like what we used while using SQL server database. In case of query its exactly like SQL query. So this is how you can use SQLite in WPF application.

[Tips] If you need to encrypt data before storing in database then visit my  previous post to learn how to encrypt and decrypt data in c#.

Thats it. Happy Coding 🙂

  • B3NN1TH

    Thank you Janak.
    For connection over network, the db file path passed in the connection needs to be have additional backslashes added in the beginning \\NetworkNameafoldersomewherepath to db file.sqlite

    • B3NN1TH

      for use with multiple users to access inside the application over network …

      string connectionString = “Data Source=\\NetworkNameafoldersomewheredb.sqlite”;

      SQLiteConnection conn = new SQLiteConnection(connectionString);