Integer c=0;
DatabaseHelper dbh1 = new DatabaseHelper(this);
Cursor ca = dbh1.getReadableDatabase().query(DatabaseHelper.TABLE_NAME, null, null, null, null, null, null);
while (ca.moveToNext())
{
String Ans6 = ca.getString(ca.getColumnIndex(DatabaseHelper.VALUE6));
if ( Ans6.equals("Automatic"))
{
c+=1;
}
}
String strI = Integer.toString(c);
Toast toast=Toast.makeText(this, strI, 2000);
toast.show();
I have a SQlite database setup in android. The table has been successfully set up and I am trying to check values from column VALUE6 if it matches Automatic. The cursor has to go through every row and check the value of VALUE6 in that row and return how many rows have Automatic. Is my code right? any ideas? strI returns 0 every time i run the code.
That’s a brute force way of doing it. Why not query for that value and then get the count of the rows in the returned cursor?
Hope this helps!