如何在Xamarin Froms中使用SqLite?

时间:2018-02-28 10:58:06

标签: sqlite xamarin.forms

的所有人。

我在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

谢谢。

1 个答案:

答案 0 :(得分: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);
        }
    }
}
相关问题