I have one registration form which is connected to database.When i insert the record the recent record comes first in table.I want recent record to be appeared below the last entered record.
Can you help me out there?
long flag = 0;
int id = 1;
SQLiteDatabase db = helper.getWritableDatabase();
Cursor cursor = db.query("tbl_countries", new String[]{"count(*) phone"}, null, null, null, null, null);
while(cursor.moveToNext())
{
int idFromDatabase = cursor.getInt(cursor.getColumnIndex("phone"));
if(idFromDatabase != 0)
{
id = 1 + idFromDatabase;
}
}
ContentValues values = new ContentValues();
//values.put("ID", id);
values.put("phone", Long.parseLong((phone.getText().toString())));
values.put("fname", fnametxt.getText().toString().trim());
values.put("lname", lnametxt.getText().toString().trim());
if(male.isChecked())
{
values.put("gender","male");
}
else
values.put("gender", "Female");
values.put("email", emailtxt.getText().toString());
values.put("mainpin",pin1.getText().toString()+pin2.getText().toString()+pin3.getText().toString()+pin4.getText().toString());
flag = db.insert("tbl_countries", null, values);
if(flag != -1)
{
Toast toast = Toast.makeText(getApplicationContext(), "You have successful inserted this record into database! "+flag, Toast.LENGTH_LONG);
toast.show();
db.close();
return;
}
else
{
Toast toast = Toast.makeText(getApplicationContext(), "An error occured when insert this record into database!", Toast.LENGTH_LONG);
toast.show();
db.close();
return;
}
Please Suggest me if anything is wrong in my code.
What can you do is give id (auto increment) column in your Registration table
and when you query your data at that time get it by ascending order for id column
thats it.