0

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);
}
6
  • please post the db adapter class also Commented Jun 18, 2012 at 6:30
  • 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; } Commented Jun 18, 2012 at 6:31
  • Use ContentValues for update. Have a look at this blog and use their example app Commented Jun 18, 2012 at 6:32
  • does the table have a default value? it needs to have atleast a single value where the currentlevel>= slevel. Commented Jun 18, 2012 at 6:45
  • In log it returns the slevel value. Database remains same as default value. Commented Jun 18, 2012 at 7:29

5 Answers 5

2

Here you go

db.update("level",args,"currentlevel>= ?", new String[] { String.valueOf(level) });
Sign up to request clarification or add additional context in comments.

Comments

0

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;
}

1 Comment

I have created the table sqlite manager tool, will it be a problem.
0

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;

      }

Comments

0

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+"");

Comments

0

Try this,

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.