【问题标题】:import already created sqlite database (xamarin)导入已创建的 sqlite 数据库(xamarin)
【发布时间】:2023-04-10 13:20:01
【问题描述】:

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

【问题讨论】:

    标签: android sqlite xamarin.android android-sqlite monodevelop


    【解决方案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();
                }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-13
      相关资源
      最近更新 更多