2012-02-17 77 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... 
} 

希望有帮助。