I am trying to find the number of rows n a sqlite table using this code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Gets the data repository in write mode
SQLiteDatabase mydatabase = openOrCreateDatabase("app_alldata",MODE_PRIVATE,null);
mydatabase.execSQL("CREATE TABLE IF NOT EXISTS userinfo(Username VARCHAR,Password VARCHAR);");
Cursor cursor = mydatabase.rawQuery("SELECT COUNT(*) FROM userinfo;",null);
int cnt = cursor.getCount();
String letsee = Integer.toString(cnt);
final TextView textViewToChange = (TextView) findViewById(R.id.mytext);
textViewToChange.setText(letsee);
}
When I run the app, i always see the number "1" in the textview, even though I am sure that the row count is not 1.
what's wrong with my code?
Note: the app doesn't crash and I don't get any errors.
Aucun commentaire:
Enregistrer un commentaire