Reputation: 121
I made a Table like below
columns:
KEY_ID(AUTOINCREMENT AND PRIMARY KEY),
KEY_DATE,
KEY_ACCOUNT_NAME,
KEY_CATEGORY,
KEY_COST,
KEY_EXPLANATION
I want to update a row which matches the KEY_ACCOUNT_NAME
But it gives me error..
Now I have two rows in the table which have AAA, BBB as KEY_ACCOUNT_NAME each.
And following query gives me the error like below.
(ai.getAccount_name()
is the target KEY_ACCOUNT_NAME value which is AAA.)
db.update(TABLE_AI, values, KEY_ACCOUNT_NAME + "=" + ai.getAccount_name(), null);
Error:
11-20 11:55:26.258: E/AndroidRuntime(1738): android.database.sqlite.SQLiteException: no such column: AAA (code 1): , while compiling: SELECT * FROM accountInfoTable WHERE account_name = AAA
Should I change the primary key from KEY_ID to KEY_ACCOUNT_NAME?
Or it is not related to the problem?
Upvotes: 0
Views: 82
Reputation: 121
Thank you for your kind help. I can't solve this problem without your help.
I change my code adding ' ' to the value.
db.update(TABLE_AI, values, KEY_ACCOUNT_NAME + " = " + name, null);
db.update(TABLE_AI, values, KEY_ACCOUNT_NAME + " = '" + name+"'", null);
I should say thanks to you early, but I have similar problems in my DBAdapter.java, so I had busy time fixing it.
And other answers work just fine as well
db.update(TABLE_AI, values,KEY_ACCOUNT_NAME + " = ?",
new String[] {ai.getAccount_name()});
Upvotes: 0
Reputation: 859
db.update(TABLE_AI, values,KEY_ACCOUNT_NAME + " = ?",
new String[] {ai.getAccount_name()});
Try this one.
Upvotes: 3
Reputation: 792
Please try this code,
int i=db.update(TABLE_AI, values, KEY_ACCOUNT_NAME + " =? " , new String[] {ai.getAccount_name()});
System.out.println("i="+i);
If i>0, then some updated, else no row update.
Upvotes: 1
Reputation: 47817
try this pass string value to '
db.update(TABLE_AI, values, KEY_ACCOUNT_NAME + "='" + ai.getAccount_name()+"'", null);
Upvotes: 1