如何在Xamarin Forms中使用SqLite?

问题描述 投票:1回答:1

大家。

我在Xamarin Forms中使用SqLite。为此我使用SqLite - PCL nuget。现在的问题是,它在Android中运行良好。但是在UWP中我无法访问数据库文件。我正在为两个平台使用通用代码。如下:

database = new SQLiteConnection(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "mydb.db"));
database.CreateTable<Item>();

我在UWP app中遇到的错误。 Error Screen Shot

谢谢。

sqlite xamarin.forms
1个回答
2
投票

docs包含有关如何在UWP中执行此操作的明确说明

using Windows.Storage;
...

[assembly: Dependency(typeof(FileHelper))]
namespace Todo.UWP
{
    public class FileHelper : IFileHelper
    {
        public string GetLocalFilePath(string filename)
        {
            return Path.Combine(ApplicationData.Current.LocalFolder.Path, filename);
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.