lundi 4 avril 2016

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 Could not find Windows Runtime type 'Sqlite.Sqlite3'.":"Sqlite.Sqlite3". 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.WindowsPhone8.SQLitePlatformWP8();
            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 connection = new SQLiteAsyncConnection(() => new SQLiteConnectionWithLock(platform, param));

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

Aucun commentaire:

Enregistrer un commentaire