【发布时间】:2023-04-10 13:20:01
【问题描述】:
我正在使用 Xamarin,想知道如何导入我已经创建的 sqlite 数据库。到目前为止,我已将其添加到资产文件夹,但不知道下一步从哪里开始。
【问题讨论】:
标签: android sqlite xamarin.android android-sqlite monodevelop
我正在使用 Xamarin,想知道如何导入我已经创建的 sqlite 数据库。到目前为止,我已将其添加到资产文件夹,但不知道下一步从哪里开始。
【问题讨论】:
标签: android sqlite xamarin.android android-sqlite monodevelop
string localPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), YourAppName);
//Directory with your DB3 file
var dirx = Android.OS.Environment.ExternalStorageDirectory.ToString();
// DB File
var dbfile = System.IO.Path.Combine(dirx , "/YourAppName/YourSQLiteDB.db3");
if (File.Exists(dbfile))
{
File.Copy(dbfile, localPath, true);
Toast.MakeText(this, "SQLiteDB copied successfully!", ToastLength.Long).Show();
}
else
{
Toast.MakeText(this, "copy from " + diry + System.Environment.NewLine + "to " + localPath + " failed or source file is missing!", ToastLength.Long).Show();
}
}
【讨论】: