viv*_*oid 91 sql sqlite android
我需要在我的应用程序中实现SQLite.我遵循了本教程. 在Android中创建和使用数据库
一切都很好.我插入了一行5列.现在我想只更新1列的值,其他的将保持不变.
教程中有一个更新方法,但它需要所有参数,但我只想更新一列.
Nik*_*hil 165
您可以使用以下代码.
String strFilter = "_id=" + Id;
ContentValues args = new ContentValues();
args.put(KEY_TITLE, title);
myDB.update("titles", args, strFilter, null);
Run Code Online (Sandbox Code Playgroud)
lui*_*tic 118
你可以试试:
db.execSQL("UPDATE DB_TABLE SET YOUR_COLUMN='newValue' WHERE id=6 ");
Run Code Online (Sandbox Code Playgroud)
要么
ContentValues newValues = new ContentValues();
newValues.put("YOUR_COLUMN", "newValue");
db.update("YOUR_TABLE", newValues, "id=6", null);
Run Code Online (Sandbox Code Playgroud)
要么
ContentValues newValues = new ContentValues();
newValues.put("YOUR_COLUMN", "newValue");
String[] args = new String[]{"user1", "user2"};
db.update("YOUR_TABLE", newValues, "name=? OR name=?", args);
Run Code Online (Sandbox Code Playgroud)
Ste*_*han 53
这一切都在教程中如何做到这一点:
ContentValues args = new ContentValues();
args.put(columnName, newValue);
db.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null);
Run Code Online (Sandbox Code Playgroud)
使用ContentValues设置更新的列,比update()中,你必须specifiy方法,表和标准,只更新需要更新的行.
Ale*_*man 18
你总是可以执行SQL.
update [your table] set [your column]=value
Run Code Online (Sandbox Code Playgroud)
例如
update Foo set Bar=125
Run Code Online (Sandbox Code Playgroud)