System.Data
assemblies to your installation, put them in the correct place AND add references to your MonoDevelop solution for Mono.Data.Sqlite.dll, Mono.Data.Tds.dll, System.Data.dll, System.Transactions.dll
(I'm not sure if they're all required, but it seemed like a sensible set).It's pretty easy to use after all that:
// db is the path to the SQLite database fileand
var conn = new SqliteConnection("Data Source=" + db);
listData = new List<Employee>();Cool eh? Doesn't that look familiar... good old ADO.NET :-)
// System.Data from http://monotouch.net/Documentation/System.Data
var sd = new SystemDataHelper("phonebook");
var connection = sd.GetConnection();
using (var cmd = connection.CreateCommand())
{
connection.Open ();
cmd.CommandText = "SELECT Firstname, Lastname, Work, Mobile,"
+ " Department, Email "
+ " FROM Phonebook ORDER BY Lastname";
using (var reader = cmd.ExecuteReader ())
{
while (reader.Read ())
{
var emp = new Employee();
emp.Firstname = (string)reader["Firstname"];
emp.Lastname = (string)reader["Lastname"];
emp.Work = (string)reader["Work"];
emp.Mobile = (string)reader["Mobile"];
emp.Department = (string)reader["Department"];
emp.Email = (string)reader["Email"];
Console.WriteLine("Column {0}",reader["Lastname"]);
listData.Add(emp);
}
}
}
THE CODE
That's a small part of the
System.Data
namespace, so the code is pretty small :) here 'tis Corp411.3.zip (38Kb)... and proof it runs on a device ...
Your sqlite3 version is old - please upgrade to at least v3.5.0!
ReplyDeleteUnhandled Exception: System.EntryPointNotFoundException: sqlite3_next_stmt
trhow exeption conexion.open()
This was discussed on the mailing list. It occurs in the simulator on Leopard (MacOS 10.5) but does NOT occur on Snow Leopard (10.6). It should also work fine on a device (regardless of the OS you're developing with).
ReplyDeleteJonathan Pryor said: "So what appears to be the problem is that when running within the simulator, instead of picking up the libsqlite3.dylib provided by iPhoneSimulator.platform, it instead picks up /usr/lib/libsqlite3.dylib. Snow Leopard's libsqlite3.dylib is a more recent version than Leopard's (and Snow Leopard's apparently better matches what's on the device), which is why it works on both Snow Leopard Simulator & the device."
and on 3rd November
"This should be fixed in the next MonoTouch release."