machu
machu

Reputation: 111

How to update data in Sqlite?

In my android application I am using sqlite database. I use the following code to update data but the data is not updated.

public int setCurrentLevel(int level)
{
  //update table level set currentlevel = level;
  int slevel = level;
  Log.d("QUIZ APP", "inside on setcreatelevel is "+slevel);
  ContentValues args = new ContentValues();
  args.put("currentlevel", slevel);

  return db.update("level", args, "currentlevel" + ">=" + slevel, null);
}

Upvotes: 0

Views: 2375

Answers (5)

Alberto
Alberto

Reputation: 11

Try this,

ContentValues cv = new ContentValues();
cv.put("Field", value);
db.update("Table", cv, "Field='value'", null);

Upvotes: 0

Vipul
Vipul

Reputation: 28093

Here you go

db.update("level",args,"currentlevel>= ?", new String[] { String.valueOf(level) });

Upvotes: 2

Anu
Anu

Reputation: 562

use this query......... also mention some condition on which you want to fire this update

      db.execSQL("UPDATE "+tableName+" SET "+columnNameValue+" WHERE "+condition+"");

your query will look something like:

    db.execSQL("UPDATE level SET currentlevel="+slevel +" WHERE currentlevel \\>=" + slevel+"");

Upvotes: 0

Harneet Kaur
Harneet Kaur

Reputation: 4497

Try This

    public int setCurrentLevel(int level)
   {
            //update table level set currentlevel = level;
            int slevel = level;
            Log.d("QUIZ APP", "inside on setcreatelevel is "+slevel);
            ContentValues args = new ContentValues();
            args.put("currentlevel", slevel);
             return db.update("level", args, 
                 "currentlevel" + ">=" + slevel, null)>0;

      }

Upvotes: 0

Om3ga
Om3ga

Reputation: 32823

Use this kind of code inside your function

public boolean updateTitle(long rowId, String isbn,
String title, String publisher)
{
ContentValues args = new ContentValues();
args.put(KEY_ISBN, isbn);
args.put(KEY_TITLE, title);
args.put(KEY_PUBLISHER, publisher);
return db.update(DATABASE_TABLE, args,
KEY_ROWID + "=" + rowId, null) > 0;
}

Upvotes: 0

Related Questions