Wednesday, February 1, 2012

How to retrive the data from SQLite table and store it in the arrayList?

Below is the example.........


private void getDataForReset() {
DBAdapter databaseManager=DBAdapter.getSharedObject(this);
SQLiteDatabase sqdb = databaseManager.getWritableDatabase();
Cursor cursor =sqdb.rawQuery("SELECT * FROM TableName WHERE MonthId='" + mmonthId+"'  AND Id='"+mId+"' ORDER BY ProductName",null);
Log.e("DownLaod All", String.valueOf(sqdb));
try {
int count = cursor.getCount();
if (!(count == 0)) {
cursor.moveToFirst();
for (int i = 0; i < count; i++) {
reset_productIdArray.add(cursor.getString(cursor.getColumnIndexOrThrow("ProductId")));
reset_totalInUnitArray.add(cursor.getString(cursor.getColumnIndexOrThrow("TotalInUnit")));
reset_totalInRupeesArray.add(cursor.getString(cursor.getColumnIndexOrThrow("TotalInRupees")));
cursor.moveToNext();
}
} else {
cursor.deactivate();
cursor.close();
sqdb.close();
       }
}
catch(Exception E){}
cursor.deactivate();
cursor.close();
sqdb.close();
}


No comments:

Post a Comment