2

My Java code Update Data base Table

String qq="UPDATE ChallanItems SET Recieve ="+str+" WHERE ItemNo = "+code;
                    Log.d("Qry", qq);
                     myDbHelper.updatequery(qq);

updatequery method

public void updatequery(String qry)
    {
        Cursor c = myDataBase.rawQuery(qry, null);


        Log.d("Up", ""+c.getCount());
    }

When i updated Data base the count return 0 and table not updated

I am using this Also but not work

String qq="UPDATE ChallanItems SET Recieve ="+str+" WHERE ItemNo = "+"'"+code+"'";

Please Help Me how i can fix this problem

Thanks In Advance

1
  • use sqLiteDatabase.update(YOUR_TABLE, where clause, YOUR_VALUES);. YOUR_VALUES is the object of ContentValues Commented Jun 2, 2014 at 7:17

3 Answers 3

7

Use execSQL() for such SQL and not rawQuery().

rawQuery() just compiles the SQL but does not run it. You'd need to call one of the move...() methods on the returned Cursor to execute a step of the compiled SQL program.

execSQL() both compiles and runs the SQL program.

There's also possibly a syntax problem with your literals - use parameters i.e. ? placeholders in SQL and String[] bind arguments to be safe.

Sign up to request clarification or add additional context in comments.

Comments

2

To update sqlite query change

 Cursor c = myDataBase.rawQuery(qry, null);

to this

myDataBase.execSQL(qry);

Comments

1

try to use this:

ContentValues values = new ContentValues();
values.put("Recieve", str);
db.update("ChallanItems", values2, "ItemNo = ?", new String[] { code });

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.