简体   繁体   中英

How to use the SQLite in xamarin.forms windows phone 8 project?

I've created a Xamarin.Forms project having Android, iOS and Windows Phone. I'm trying to use the Sqlite Database in Xamarin Windows Phone 8.1 project and I've installed the sqlite.net pcl and core and async libraries with platform library. When I try to run the project it shows an error winrt.dll sqlite3 could not be found. There are actually two reference libraries for sqlite.platforms.windowsPhone8 so I've added it as x86 but still having problem. Here is my code for windows phone 8.1

    namespace SwachhParyatanApp.WinPhone
{
    class DBPath_WinPhone : IDBPath
    {
        public SQLiteAsyncConnection GetDBPath()
        {
            var path = Path.Combine(ApplicationData.Current.LocalFolder.Path, "localData.db");
            var platform = new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT();
            var param = new SQLiteConnectionString(path, false);
            var connection = new SQLiteAsyncConnection(() => new SQLiteConnectionWithLock(platform, param));
            return connection;
        }
    }
}

Whenever I try to call using the dependency service its shows error on the line var platform = new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT();

By default the WinRT library was added to the project but it was also having problem so I added the windowsphone8 library.

Windows phone does not included the SQLite, like iOS and Android.

You need to download the SQLite extension for VS, and reference it in your project.

I would recommend using the SQLite-net PCL , it's an ORM for SQLite and provides nice async/synchronous APIs on top of regular SQLite APIs

我找到了答案,我们需要从sqlite.org中为Windows Phone 8.1 WinRT站点手动添加sqlite3.dll。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM