简体   繁体   中英

Update Query not working in Android Sqlite

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

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 ie ? placeholders in SQL and String[] bind arguments to be safe.

try to use this:

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

To update sqlite query change

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

to this

myDataBase.execSQL(qry);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM