誰かがMonodroidでsqliteを使用する例を教えていただけますか?私は1つでも見つけられませんでした。Monodroidでsqliteの例が必要です
17
A
答えて
36
明らかに、SQLiteデモをApiDemoサンプルに追加する必要があります。
ことが起こるだろうとき、私は知らないので、ここでは、迅速かつ汚いバージョンです:
は、次のコードを使用して、ただしは Mono.Dataを使用するには、Android 2.2以降をターゲットにする必要があります。 Sqlite。以前のAndroidバージョンをターゲットにする必要がある場合は、managed-sqliteのように、完全に管理された置き換えを調べる必要があります。
さらに、この例ではMono.Data.Sqlite.dllを使用しています。これはMonoDroid SDKに含まれています。
まず、プロジェクトアセンブリの参照を編集し、Mono.Data.Sqlite.dll
とSystem.Data.dll
の参照を追加します。ソースコード内の
第二に、追加します。
using System.Data;
using Mono.Data.Sqlite;
最後に、使用がた通常のADO.NETコード:あなたはSQLiteのでの作業のヒントが必要な場合は
string dbPath = Path.Combine (
Environment.GetFolderPath (Environment.SpecialFolder.Personal),
"items.db3");
bool exists = File.Exists (dbPath);
if (!exists)
SqliteConnection.CreateFile (dbPath);
var connection = new SqliteConnection ("Data Source=" + dbPath);
connection.Open();
if (!exists) {
// This is the first time the app has run and/or that we need the DB.
// Copy a "template" DB from your assets, or programmatically create one.
var commands = new[]{
"CREATE TABLE [Items] (Key ntext, Value ntext);",
"INSERT INTO [Items] ([Key], [Value]) VALUES ('sample', 'text')"
};
foreach (var command in commands) {
using (var c = connection.CreateCommand()) {
c.CommandText = command;
c.ExecuteNonQuery();
}
}
}
// use `connection`...
// here, we'll just append the contents to a TextView
using (var contents = connection.CreateCommand()) {
contents.CommandText = "SELECT [Key], [Value] from [Items]";
var r = contents.ExecuteReader();
while (r.Read())
MyTextView.Text += string.Format ("\n\tKey={0}; Value={1}",
r ["Key"].ToString(), r ["Value"].ToString());
}
connection.Close();
関連する問題
- 1. MonoDroidとMVVMCrossで写真を撮る例が必要です
- 2. AppDelegateのSQLiteが必要ですか?
- 3. MonoDroid、SQLite、LINQ
- 4. SQLiteデータベースのヘルプが必要
- 5. SQLiteデータベースのヘルプが必要
- 6. sbt 0.11タスクの例が必要です
- 7. SQLiteデータベースでCursorLoaderで使用するURIが必要です
- 8. Xcode、iphone、Sqlite、グループのサイン機能が必要ですか?
- 9. 空のsqliteデータベースには74 Mbが必要ですか?
- 10. CoreTextとsqliteに関するアドバイスが必要です
- 11. 私はJAVA(nullpointer例外)のプログラムで助けが必要です
- 12. SQLiteクエリ - 全文検索でのヘルプが必要
- 13. Actionscript APIのFacebook PublishのPublishPostメソッドの例が必要です
- 14. MonoDroid:未処理例外リカバリ
- 15. Qtでstd :: vectorを使用した例が必要です
- 16. Python例外の後にreturn文が必要ですか?
- 17. Android ProtoBuf RPCの例が必要ですか?
- 18. Cirqus: "シーケンス番号0のイベントが必要です"例外
- 19. URLTriggerプラグイン。 TXT-RegExまたはXML-XPathの例が必要です
- 20. AndroidアプリのJavaソケット例外、ヘルプが必要ですか?
- 21. UIBarButtonItemの外観例外が必要です
- 22. にAES解読の例が必要
- 23. RecyclerView.Adapter.notifyItemChanged(int position、Object payload)の例が必要
- 24. TypeWatchの使用例が必要
- 25. Perl 6での単純な並列処理の例が必要
- 26. MonoDroidでのローカライゼーション
- 27. FLEXアプリケーションでカスタムコンポーネントを使用する例が必要
- 28. Java EE WildFly 8.2トランザクションが必要です例外
- 29. TypeScriptでfabricjs.d.tsを使用する例が必要
- 30. オーディオデータ?私は典型的な例が必要です
を私もブログ記事を書きましたここに:http://www.elucidsoft.com/blog/2011/12/31/mono-android-working-with-sqlite/ – emalamisura