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!!


2 comments:

Unknown 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.

Chad said...

Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Visit here for Penetration testing services and Software testing services