我有一个连接到数据库的注册表单。当我插入记录时,最近的记录在表中排在第一位。我希望最近的记录出现在最后输入的记录下方。你能帮我吗?
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;
}
如果我的代码有任何问题,请建议我。