导入已创建的sqlite数据库(xamarin) [英] import already created sqlite database (xamarin)

查看:158
本文介绍了导入已创建的sqlite数据库(xamarin)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Xamarin,想知道如何导入已经创建的sqlite数据库.到目前为止,香港专业教育学院将其添加到资产文件夹,但不知道下一步从哪里开始.

I'm using Xamarin and want to know how to import an sqlite database I've already created. So far ive added it to the assets folder but dont know where to start next.

推荐答案

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();
            }
}

这篇关于导入已创建的sqlite数据库(xamarin)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆