0

Here is my question. I have one table like this

alias  id  age
-----  --  ---
A0      1  23
A0      2  12
A0      3  32
B0      1  45
B0      2  80
B0      3  56
C0      1  __
C0      2  __
C0      3  __

and I want to extract with the help of a cursor only the rows with the same alias, for example: only the rows that starts with B0. I've found this:

createIndexCursor(Table table, Index index,Object[] startRow, Object[] endRow) 

using this example how do I set index, starRow and endRow???

I will fill a gridview with this data and once the user edit one empty field I will save that row from the gridview into a map, so I found this method:

 asUpdateRow(Map<String,?> rowMap)

So how can I update the row of the table using the attributes

  gridView.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View v,
            int position, long id) {

in order to save data in the exact position?

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418

1 Answers1

0

I want to extract with the help of a cursor only the rows with the same alias, for example: only the rows that starts with B0

Assuming that you have an index on the alias column, you could build a cursor for only the 'B0' rows and then extract those rows into an ArrayList like this

Database db = DatabaseBuilder.open(new File(
        "C:/Users/Gord/Desktop/Database1.accdb"));
Table tbl = db.getTable("MyTable");
Cursor crsr = new CursorBuilder(tbl)
        .setIndex(tbl.getIndex("alias"))
        .setStartEntry("B0")
        .setEndEntry("B0")
        .toCursor();
List<Row> rowList = new ArrayList<Row>();
for (Row r : crsr.newIterable()) {
    rowList.add(r);
}

Then, if you wanted to update the database with a new age value for one of the rows you could do it like this:

// update "age" for the first row in the ArrayList (index=0)
rowList.get(0).put("age", "77");
tbl.updateRow(rowList.get(0));
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418