Updating Or Inserting In A Table With Keeping The Row Numbers To One
I am trying to see if there is something in my table update it and if not insert one row. So basically I will have one row always in my table. public void createOrupdate(long
Solution 1:
The check for c!=null
is not enough. The cursor can be not null even when the result of the query was empty. That means you need to get the amount of rows by using c.getCount()
and check if that returns 0
or 1
.
PS: This for( c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
is a pretty ugly use for a loop. You should change that to something like while(c.moveToNext())
.
moveToNext()
will be the same like moveToFirst()
on a fresh created cursor object.
Post a Comment for "Updating Or Inserting In A Table With Keeping The Row Numbers To One"