2012-02-17 71 views
3

我是新開發的iPad。我使用Xcode 4在Objective C中創建了兩個或三個iPad應用程序。現在我想在使用C#的MonoDevelop工具中創建iPad應用程序。如何爲iPhone創建一個SQLite數據庫?

我想創建一個基本的數據庫項目,爲此我需要一個基本的教程,它使用SQLite數據庫。我在谷歌搜索,但我沒有任何教程。

+0

如果不知道Mono.Data.Sqlite命名空間工程MonoTouch的,但另一種可能的方法是使用C#-SQLite,http://code.google.com/p/ csharp-sqlite – 2012-02-17 05:36:11

+0

我需要數據庫相關的教程,用於開發iPhone,但在C#語言中使用Monodevelop工具 – Krunal 2012-02-17 05:37:17

+1

重複:http://stackoverflow.com/questions/7952306/how-to-create-database-and-table-in- sqlite-programatically-using-monotouch/7959026#7959026 – Anuj 2012-02-17 05:40:28

回答

5

要訪問源碼,你有很多選擇,像

  1. http://code.google.com/p/sqlite-net/非常有用的,我的首選方法
  2. System.Data和Mono.Data.SQLite http://docs.xamarin.com/ios/advanced_topics/system.data
  3. 的EntityFramework的單http://www.taimila.com/entify/index.php(唐」 t知道它是否仍在開發中)
  4. Vici酷存儲這裏是一個很好的博客文章關於它http://blog.activa.be/index.php/2010/02/vici-coolstorage-orm-on-monotouch-made-simple/和Vici的頁面http://viciproject.com/wiki/projects/coolstorage/home

和許多其他人甚至蘋果公司的CoreData看到(http://www.sgmunn.com/?p=1)但我猜上面的任何選項都比較容易。

希望這有助於讓你開始

8

我已經嘗試過SqLiteClient和SqLite-net。我建議你在這裏閱讀教程: sqlite-net

對我來說,我只是將Sqlite.cs文件放到我的項目中,並用它編譯。

然後,使用您選擇的工具,創建一個SQLite數據庫並將其添加到您的MonoTouch項目中,確保將構建標誌設置爲「內容」。一旦你的項目中有了SQLite數據庫(把文件放在你喜歡的任何地方),你可以通過只讀的方式訪問它......除非你做了類似於下面例子中的代碼的東西......哪些位置可以重定位將文件存儲到您的應用(和您的用戶)將擁有寫入權限的用戶個人文件夾中。

如果您需要的用戶,在運行時,做CRUD操作對數據庫,你需要在你的代碼是這樣的,包括將文件複製到用戶的個人文件夾:

using System.Linq; 
using SQLite; 

string personalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal); 
string dbName = "myDatabase.db"; 
string dbPath = Path.Combine (personalFolder, dbName); 

// in this example I will always delete and re-copy the db to the users personal folder... 
// modify to suit your needs... 
if (File.Exists (dbPath) { 
    File.Delete(dbPath); 
} 
File.Copy (dbName, dbPath); 
// note: myDatabase.db for this example is in the root project folder. 

using (var db = new SQLiteConnection(dbPath)) { 
    // query using Linq... 
} 

希望有幫助。