Under UWP, it sometimes makes sense to create a local database for the application.
It is important that the database is easily created on-the-fly at runtime.
That's why the Sqlite database is best suited here.
This has also been equipped with EF Entity Framework and Linq since 2018.
Note: Since the Windows 10 Anniversary Update (build 14393), SQLite is part of Windows 10.
This means that you only have to use Microsoft.data.SQLite as the reference
Installation in UWP App
In Visual Studio, select the project and in the context click on -> Manage NuGet Packages.
In the NuGet Package Manager, enter: sqlite in Browse and select the package
Microsoft.Data.Sqlite from Microsoft
SQLite implementation of the System.Data.Common provider model.
Commonly Used Types: Microsoft.Data.Sqlite.SqliteCommand Microsoft.Data.Sqlite.SqliteConnection Microsoft.Data.Sqlite.SqliteConnectionStringBuilder Microsoft.Data.Sqlite.SqliteDataReader Microsoft.Data.Sqlite.SqliteException Microsoft.Data.Sqlite.SqliteFactory Microsoft.Data.Sqlite.SqliteParameter Microsoft.Data.Sqlite.SqliteTransaction |
Include in C # Code
In the UWP page MainPage.cs enter the namespace Microsoft.Data.SQlite in the Using header
//< using > using HtmlAgilityPack; //HtmlDocument using System.Net; //*WebRequest using System.Threading.Tasks; //*Task using Microsoft.Data.Sqlite; //*SQLite for UWP from Microsoft //</ using > |
Subsequently, the database can be created at runtime while the main page is opened
public MainPage() { this.InitializeComponent(); optStop.IsChecked = false;
//SqliteEngine.UseWinSqlite3(); //Configuring library to use SDK version of SQLite using (SqliteConnection db = new SqliteConnection("Filename=Projects.db")) { db.Open(); String tableCommand = "CREATE TABLE IF NOT EXISTS MyTable (Primary_Key INTEGER PRIMARY KEY AUTOINCREMENT, Text_Entry NVARCHAR(2048) NULL)"; SqliteCommand createTable = new SqliteCommand(tableCommand, db); try { createTable.ExecuteReader(); } catch (SqliteException e) { //Do nothing } } }
|
Read SQLite data
Reading and writing data in the SQLite database is pretty easy
SQLiteConnection dbConnection = new SQLiteConnection("Folders.db"); |
For data processing one finds then https://blogs.windows.com/buildingapps/2017/02/06/using-sqlite-databases-uwp-apps/#k24zYWkVYzaczTzM.97