我正在使用Xamarin并想知道如何导入我已创建的sqlite数据库。到目前为止,我已将其添加到资源文件夹中,但不知道下一步该从哪里开始。
答案 0 :(得分:1)
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();
}
}