2015-02-06 160 views
0

我想在我的應用程序(Xamarin.Android)上創建一個數據庫。我使用本教程 http://developer.xamarin.com/recipes/android/data/databases/sqlite/Visual Studio + Xamarin:創建數據庫SQLite

但該網站沒有闡明有關參數path

private string createDatabase(string path) 
{ 
    try 
    { 
     var connection = new SQLiteAsyncConnection(path);{ 
      connection.CreateTableAsync<person>(); 
      return "Database created"; 
    } 
    catch (SQLiteException ex) 
    { 
     return ex.Message; 
    } 
} 

誰能幫助我,這個參數?

我嘗試用「/app1/databases/dbPEduc.db」,但顯示了異常:

SQLite.SQLite3+Result.CannotOpen 

回答

1

documentation爲Xamarin SQLite的組件具有正確的路徑的例子使用(下異步API

string folder = Environment.GetFolderPath (Environment.SpecialFolder.Personal); 
var conn = new SQLiteAsyncConnection (System.IO.Path.Combine (folder, "stocks.db")); 
conn.CreateTableAsync<Stock>().ContinueWith (t => { 
    Console.WriteLine ("Table created!"); 
}); 
+0

感謝'@ JASON'這個工作完美... – 2015-02-09 19:32:26