xamarin - 如果没有这样的数据库,如何检查 Xamarin 中是否存在 SQLite 数据库文件并创建一个新的数据库文件?
问题描述
我正在尝试编写一种检查 SQLite 文件存在的方法。我下载了一个名为 System.Data.SQLite.Core 的用于 SQLite 功能的 Nuget 包。我为该方法编写了以下代码:
string path = "ReportData.db";
private void Create_db()
{
if (!System.IO.File.Exists(path))
{
SQLiteConnection.CreateFile(path);
using (var sqlite = new SQLiteConnection(@"Data Source=" + path))
{
sqlite.Open();
string sql = "create table temp(date varchar(20),activity varchar(1000))";
SQLiteCommand command = new SQLiteCommand(sql, sqlite);
command.ExecuteNonQuery();
sqlite.Close();
}
}
}
我不知道在哪里创建我的 SQLite 数据库文件。当我在按钮中使用此方法时,应用程序进入中断模式并说:
System.UnauthorizedAccessException:'访问路径“/ReportData.db”被拒绝。'
请帮我。
解决方案
推荐阅读
- java - 如何将链接存储到速度变量中并在 html 中显示?
- android - 在 webview 中下载文件返回错误数据
- javascript - React TypeScript:关键系统
- r - 分别为每个 df 运行一个 lm 模型
- c# - 反射以获取类中类属性的值
- reactjs - 如何在玩笑中使用 File.text()?
- octave - 在开始我的代码之前,如何将 Octave 中所有变量的精度设置为“固定位数”?
- java - 在改造模型中将不同的数据传递给同名的json属性
- spring-boot - 由于 Kafka 常见指标,Spring Boot 内存不足
- flutter - 如果 ListView 包含 FutureBuilder,为什么 PageStorageKey 不起作用?