I want to fetch data from table "student" in SQLite android database
and here is the method that I use to retrieve the data
public Cursor getAllStudent(){
SQLiteDatabase db= helper.getWritableDatabase();
String[] columns={"_id",
"'reg_number'",
"'School_id'",
"'class_id'",
"'first_name'",
"'last_name'",
"'PPN'",
"'photo'",
"'CyncStatus'"};
Cursor cursor=null;
try {
cursor = db.query("student",columns,null, null,null,null,null);
} catch (Exception e) {
// TODO Auto-generated catch block
Log.d("select student failed: %d", e.toString());
}
return cursor;
}
and this is how I iterate through the result
Cursor c1 = studentHelperAdapter.getAllStudent();
c1.moveToFirst();
while (!c1.isAfterLast()){
String reg = c1.getString(1); // return column name not value
String name = c1.getString(4); //return name column not value
String reg = c1.getString(5); //return name column not value
c1.moveToNext();
}
c1.close();
and I have tried to add this line below to see cursor content and I realized that no data was fetched there are only column names
Log.d("AB cursor ",android.database.DatabaseUtils.dumpCursorToString(c1));
Anyway, there 2 similar questions but none of the solutions solved my problem
Get the field value with a Cursor
How to get field value instead of column name?
I look forward to see your answer here, thanks