Nebuchad
Nebuchad

Reputation: 11

Using SQLite in an Universal Windows library without LINQ

I was previously using System.Data.SQLite in a .NET library, and now want to port this library to an Universal Windows library.

I cannot make the System.Data.SQLite work (since I guess it is not portable), and found only LINQ style SQLite PCL libraries in NuGet ...

Is there a way that I can use good all fashion queries in an Universal Windows App in order to have the same or close syntax as in System.Data.SQLite?

Something like this :

SQLiteCommand dbCommand = new SQLiteCommand(dbConnection);
dbCommand.CommandText = dbQuery;

SQLiteDataReader reader = dbCommand.ExecuteReader();

Upvotes: 1

Views: 1091

Answers (1)

Jeffrey Chen
Jeffrey Chen

Reputation: 4680

You can use the SQLite.NET-PCL in Universal Windows Platform App (search sqlite.net-pcl in NuGet).

var path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");

using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path)) 
{
    conn.CreateTable<User>();
}

The blog will introduce you the detail steps about how to use SQLite in UWP.

http://igrali.com/2015/05/01/using-sqlite-in-windows-10-universal-apps/

Upvotes: 1

Related Questions