Note that there are some explanatory texts on larger screens.

plurals
  1. POData replaced instead of insereted using SQLite on android
    primarykey
    data
    text
    <p>I am writing an android app which requires the records to be added one after another. When user types in the correct pin his profile is updated by a connected component to pin. But my app is updating instead of inserting or adding a new record. Here is my code please help me out</p> <pre><code>//Database SQLiteDatabase db=mydbhelper.getWritableDatabase(); //Openining the database db=this.openOrCreateDatabase("mm.db",MODE_PRIVATE,null); try { //Retriving the pin from db Cursor c=db.query("pin_table",null,null,null,null,null,null); c.moveToFirst(); boolean matched=false; while(c.isAfterLast()== false) { String hsname=c.getString(c.getColumnIndex("name")); String dpass=c.getString(c.getColumnIndex("pin")); int id=c.getInt(c.getColumnIndex("_id")); if(epass.equals(dpass)) { ContentValues value = new ContentValues(); value.put("reg_hs",id); //Inserting into the table db.execSQL("INSERT INTO hereg(reg_hs) VALUES("+id+");"); //db.insert("registered", null,value); Toast.makeText(this.getBaseContext(),"Successfully added "+ hsname,Toast.LENGTH_SHORT).show(); matched=true; finish(); break; } c.moveToNext(); } if(!matched) Toast.makeText(this.getBaseContext(),"Please enter the correct Password",Toast.LENGTH_SHORT).show(); c.close(); } catch(Exception e) { Log.e("Error","Error",e); } finally { if(db!=null) { db.close(); } } } </code></pre> <p>I used both execSql and also db.insert(commented) giving the same result. Is it because of the while loop?</p> <p>My problem is all records are deleted and only record is shown and latest value is written across it :(</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload