Storing data in a variable is not always useful in app development, because it will be automatically reset or deleted when the app is closed. But as a app developer, we need to store more than one variable to do something like maintaining a user profile, a game score, game levels information, and so on. Hence to store data in well-structured manner I suggest use of SQLite for Windows Phone.

SQLite is open source and it's available for nearly every platform on the market (mobile, web, client, and so on). With a simple SQL query we can insert, update, retrieve and delete data from the app storage.
So here I'm showing you a simple procedure for using SQLite for Windows Phone: You can use Video Tutorial for SQLite for Windows Phone.
1. We need to install SQLite for Windows Phone SDK in Visual Studio, so we can add reference to it. Open your project in Visual Studio and go to "Tools" >> "Extensions and Updates…".
2. Search “SQLite for Windows Phone” or "sqlite" [1] and Install it [2]. After installation Visual Studio will ask for a restart. Click on Restart to add new installed Extensions into Visual Studio.
3. Now we have to add this new installed extension. For that, right-click "References" in the project in the Solution Explorer then select "Add References…".

4. Select Windows Phone [1] then Extenstions [2] and mark on SQLite for Windows Phone [3] and then click on OK.

5. After adding the extensions we have to add some NuGet Packages. For that, right-click "References" in the project in the Solution Explorer then select "Manage NuGet Packages".

6. Search for “sqlite-net” [1] and install both packages, sqlite-net and sqlite-net-wp8 [2].
SQlite-net:
It's a wrapper for the native SQLite engine and it supports both the Windows 8 platform and Windows Phone 7 or 8.0. sqlite-net provides helper code that you will use to handle the SQLite database. It is written in C# and is meant to be simply compiled in with projects.
SQlite-net-wp8:
This provides the code between your source code and the SQLite for Windows Phone SDK. It's a C++/CX wrapper for SQLite functions that depend on sqlite-net. It can be used as an alternative library to charp-sqlite on Windows Phone 8.

7. SQLite does not support all platforms so we have to change the Build Configurations.
- Go to Solution Explorer and double-click on Properties.
- Select the Build Tab [1], change the Platform [2] using the following table and finally add one extra Conditional Compilation Symbols [3] “USE_WP8_NATIVE_SQLITE” and build the solution.
- It is required to set the proper native build engine.
Deploying and Testing On Choose Platform Emulator X86 Windows Phone Device ARM

8. Now you are ready with the SQLite environment, you can store (in other words insert), update, retrieve and delete data.
9. Create a class for representing the table. Each attribute in a class becomes an attribute in the database table.
Note: You can create a separate class with the same namespace for this or can paste in the same namespace.
By using the following code we are creating an ID, Title, Text and CreationDate that are 4 columns in a table.
- public sealed class Task
- {
- // You can create an integer primary key and let the SQLite control it.
- [PrimaryKey, AutoIncrement]
- public int Id { get; set; }
- public string Title { get; set; }
- public string Text { get; set; }
- public DateTime CreationDate { get; set; }
- public override string ToString()
- {
- return Title + ":" + Text + " << " + CreationDate.ToShortDateString() + " " +CreationDate.ToShortTimeString();
- }
- }
When sealed is applied to a class, the sealed modifier prevents other classes from inheriting from it.
In the following example, class B inherits from class A, but no class can inherit from class B.
- class A {}
- sealed class B : A {}
- // Attempting to inherit causes compiler error CS0239.
- // class C : B {}
This is an Auto-Implemented Property. It's basically a shorthand way of creating properties for a class in C#, without having to define private variables for them. They are normally used when no extra logic is required when getting or setting the value of a variable.
Instead of the following code we can write only: public string Name { get; set; }.
- public string Name
- {
- get
- {
- return name;
- }
- set
- {
- name = value;
- }
- }

10. Go to MainPage.xaml.cs and add the SQLite and Windows Storage namespaces.
- using SQLite;
- using System.IO;
- using Windows.Storage;
DB_PATH: It's a database path and we create the database in an app storage area so that another app can't modify this database.
- // The database path.
- public static string DB_PATH =Path.Combine(Path.Combine(ApplicationData.Current.LocalFolder.Path, "sample.sqlite"));
- // The sqlite connection.
- private SQLiteConnection dbConn;





Nitin PatilPosted Apr 18, 2015, 6:08 AM
Hi Ajay,Yes this article is only for WP 8.0 if you want to develop for WP8.1 please refer https://www.youtube.com/watch?v=AEZGeTwg5kI video link
ajay kumarPosted Mar 31, 2015, 2:03 AM
Is the above procedure is only suitable for windows phone 8.0 ... i want it for wp8.1
Saravanakumar SekaranPosted Nov 6, 2014, 3:24 AM
very nice
Dinesh BeniwalPosted Nov 5, 2014, 12:10 PM
Good start Nitin, Welcome to C# Corner.
Abhishek Kumar RaviPosted Nov 5, 2014, 8:33 AM
Welcome to C# Corner, Nitin :D