While developing applications there may be a need to store data and access it for later use. Windows Phone provides us with different ways to store our application data depending on the size. But when dealing with large data involving multiple entries, database is the appropriate method.
Windows phone 8.1 Runtime app supports SQLite database. So in this article I will explain you how to install and setup SQLite database reference in your windows phone application.
Follow the steps given below
Create a new Project having the name SQLiteDatabase.
Install the SQLite for Windows phone 8.1 SDK
Go to Tools->Extensions and Updates
Then type the keyword sqlite in search bar in the online tab. And install the SDK SQLite for Windows Phone 8.1
Note: If you don’t find the required library in Visual Studio gallery you can download it from the required web page.
Add the SQLite Reference to your Project
Go to References->Windows Phone 8.1->Extensions
When done, you will see that the proper references to SQLite and Visual C++ 2013 Runtime have been added to your project
Change the target Platform of your Project
You may have already noticed, that the references show a warning symbols, to resolve that the next thing to do, before compiling the solution is changing the architecture of the target platform. This is the fact that the engine of Sqlite is written in C ++, and the default target platform set in the project is Any CPU. This mode is not supported.
So in order to resolve this go to Configuration Manager as shown in the figure below
In the next dialog, we note that we have several choices of platforms, Any CPU (the default), ARM, x64 and x86.
Now we change the target platform accordingly. If you want to debug your app on Phone then choose the ARM Platform. But if you wish to debug your app on Emulator or Windows PC select x86 or x64 configuration depending on your processor if it is 32 bits or 64 bits.
Note: Every time you change your debugging option from emulator to phone you need to change the debug configuration accordingly.
Installing sqlite-net package
After installing the library for SQLite, we need sqlite-net NuGet package. With this library, we will be able to perform all the operations that you normally do in a database, such as Insert, Delete, Update and run search queries. This package provides two helper classes (SQLite.cs and SQLiteAsync.cs).
To install it right click on the project->Manage NuGet Packages and search for sqlite-net
Finally we have completed the SQLite setup. In the next blog post I will be explaining you how to perform different operations like insertion, deletion and searching in SQLite database.