Reputation:
I'm trying to use a Cursor to retrieve data from a database that's structured like this:
_id order_id item_name item_quantity
1 1 Biscuits 20
2 1 Sugar 30
3 2 Cars 10
4 2 Tables 30
5 3 Chair 50
6 3 Board 60
7 4 Meat 30
8 4 Fish 40
I need to retrieve select order_item, order_id FROM [table_name] WHERE order_id = 1 and I tried this:
cursor.moveToFirst();
StringBuilder res=new StringBuilder();
while (!cursor.isAfterLast()) {
res.append("\n"+cursor.getString(cursor.getColumnIndex("item_name, item_quantity WHERE order_id = 1")));
cursor.moveToNext();
}
resultView.setText(res);
But it gives me error, the error means there's nothing like that in the database
Upvotes: 0
Views: 175
Reputation: 5220
here is your fault :
cursor.getColumnIndex("item_name, item_quantity WHERE order_id = 1")
I think you have to change it like this :
cursor.getColumnIndex(COLUMN_NAME_IN_TABLE)
Upvotes: 0