Reputation: 5411
I have a SQLite database with one table for cities name now I want to include this database to my monotouch project, connect to this database and select to this table. But I can find any tutorial to do this.
I don't new to create the database or create a new record. I just need to read the table.
Can anyone explain me how can I connect to my sqlite database an make a select.
Thanks in advance.
UPDATE
using(var connection = new SqliteConnection ("Data Source=zurfers.sqlite"))
{
using (var cmd = connection.CreateCommand()) {
connection.Open ();
cmd.CommandText = "SELECT * FROM City";
using (var reader = cmd.ExecuteReader()) {
while (reader.Read()) {
wordCollection = (string[])reader ["Name"];
}
}
}
}
Upvotes: 0
Views: 156
Reputation: 89214
include your DB file in your MonoTouch project and mark it as content.
using(var connection = new SqliteConnection ("Data Source=MyDatabase.sqlite"))
{
using (var cmd = connection.CreateCommand()) {
connection.Open ();
cmd.CommandText = "this is my query";
using (var reader = cmd.ExecuteReader()) {
while (reader.Read()) {
code = (string)reader ["ColumnName"];
}
}
}
}
Upvotes: 3