Using SQLite In An SQL Manner In Windows 10 Apps

SQLite for universal windows platform is a high performance mobile database which uses objects to store data. It’s opensource and a good choice for a local database option in UWP apps. There are many ways you can use SQLite and there are many versions of SQLite extensions (For example, SQLite.net , SQLite-PCL and many more).

If you have a knowledge about SQL language, then SQLite-PCL is the choice for you because it uses standard SQL statements. In this article we will learn how to perform basic database operations using SQLite-PCL. (PCL-Portable Class Library).

Step 1: Configuring the environment

In order to use SQLite we must install the SQLite extension for Visual Studio. In Visual Studio 2015 go to Tools, then Extensions and updatess. Then a window will open and go to the Online section and search for SQLite. Then press the download button and the extension will install.

sqllite

Next we must add the SQLite-PCL class library to our project. Create a new Universal app project in Visual Studio 2015. Right click on the project in the solution explorer and click ‘Manage NuGet Packages’ . Then a new tab will open and in it search for ‘SQLite-PCL’ and install it.

nuget

Now right click on the Reference in the solution explorer and select Add Reference. Go to Universal Windows> Extensions and add the references as shown below.

add refrence

Now we are ready to use SQLite databases.

Step 2: Creating the database and adding tables.

Creating a SQLite database is pretty simple. Add a new class named ‘DataOperations’ to the project and add the following code to it.

database

I have created a table named ‘Student’. You can add attributes like above.

Now we’ll create a simple Student class to hold our data.

student

Now we’ll add some sample data to our database. Add the following code to our DataOperation class.

DataOperation class

Now we want to read our data. Add the following code to our DataOperations class. This will return a list of student records we have in our database.

DataOperation class1

This is the basic syntax and only thing that will change is the SQL statements we use.

You can get more reference and statements from here.

Up Next
    Ebook Download
    View all
    Learn
    View all