Click here to Skip to main content
16,022,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Display only one field of table using database in android

I want only one field ExpNo from table where table have fields like
ExpNo, ExpName, Amt1, Amt2

But According them i want only one field to disply ExpNo which was last entered because i want last entered value(Automatically generated) + 1

Sql query like : select MAX(ExpNo) from TableName;

(please help to write it on android)


i was write the code like this :

public void dispExpNo()  
{
    String[] exno = {"ExpNo"};  
    Cursor c = db.query("tb_expense",exno,null,null,null,null,null);                
    txtExpno.setText(""+c.getInt(0));
    c.close();          
}
Posted

Take a look at
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html[^]

This will let you execute your select max() query without fiddling with the Android database help methods. You will still get a plain old Cursor back,
 
Share this answer
 
v2
C#
SqlDatabase db;
Cursor cur = db.rawQuery("SELECT MAX(_ID) FROM tb_expense;",null);
startManagingCursor(cur);    
cur.moveToFirst();

while(!cur.isAfterLast())
{
    int id  = cur.getInt(0);						
    txt id1 = id + 1;
    txtID.setText(Integer.valueOf(id1).toString());
    cur.moveToNext();
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900