I've been trying to update a specific row for a while now, and it seems that there are two ways to do this. From what I've read and tried, you can just use the:
execSQL(String sql)
method
or the:
update(String table, ContentValues values, String whereClause, String[] whereArgs)
method.
(Let me know if this is incorrect as I am new to android and very new to SQL.)
So let me get to my actual code.
myDB.update(TableName, "(Field1, Field2, Field3)" + " VALUES ('Bob', 19, 'Male')", "where _id = 1", null);
I am trying to accomplish this:
Update Field1, Field2, and Field3 where the primary key (_id) is equal to 1.
Eclipse gives me a red line right underneath the word "update" and gives me this explanation:
The method update(String, ContentValues, String, String[]) in the type SQLiteDatabase is not applicable for the arguments (String, String, String, null)
I'm guessing I'm not assigning the ContentValues correctly. Can anyone point me in the right direction?
First make a ContentValues object :
Then use the update method, it should work now:
you can try this...
//Here is some simple sample code for update
//First declare this
//initialize the following
//updation code
//put ur id instead of the 'question mark' is a function in my shared preference.
This code should fix your example:
use this code in your DB `
for updating in your sample.java use this code
Method for updation in SQLite: