android sqlite check if inserted new value

后端 未结 3 838
长情又很酷
长情又很酷 2021-01-11 16:13

I\'m working with sqlite. I successfully created database and table. I also wrote code which can insert new values in my table. My code is working perfect, but now I want to

3条回答
  •  我在风中等你
    2021-01-11 16:41

    insert() method returns the row ID of the newly inserted row, or -1 if an error occurred.

    Change

    db.insert(AddNewPhysicalPerson, null, newValues);
    

    like this

    long rowInserted = db.insert(AddNewPhysicalPerson, null, newValues);
    if(rowInserted != -1)
        Toast.makeText(myContext, "New row added, row id: " + rowInserted, Toast.LENGTH_SHORT).show();
    else
        Toast.makeText(myContext, "Something wrong", Toast.LENGTH_SHORT).show();
    

提交回复
热议问题