Sunday, August 12, 2012

SQLite.Constraint exception Xamarin Mono Android

When using SQLite and your table contains an INTEGER PRIMARY KEY be sure to make the object that you store in the table with a NULLABLE integer for the ID.

CREATE TABLE Foo (
  fooID INTEGER PRIMARY KEY,
  fooData TEXT,
  barData REAL
)

class Foo
{
   public int? fooID {get; set;}
   public string fooData {get; set;}
   public float barData {get; set;}
}

When you add to the table be sure to set the index to null

Repository.AddFoo(new Foo{ fooID=null; fooData="foo", barData=3.14159});

It took me half a day to find because the damned stupid Android debugger is so SLOOOOWW!!


1 comment:

DevRabbit IT Solutions Inc. said...

Its an informative article on "SQLite.Constraint exception Xamarin Mono Android". All your hard about curating this informative post is much appreciated. Hire now Xamarin Consultant.