0

我目前正在开发一个 Android 应用程序。数据库有 1 列仅命名的内容。这是代码:

 public long insert(String content){

  ContentValues contentValues = new ContentValues();
  contentValues.put(KEY_CONTENT, content);
  return sqLiteDatabase.insert(MYDATABASE_TABLE, null, contentValues);
 }

如何更新该数据库中的特定列(根据其索引)?

4

2 回答 2

1
db.update
(
  MYDATABASE_TABLE, contentValues , ID_FIELD_CONST + " = ?", 
  new String[] { idValue }
);
于 2013-05-06T16:17:29.913 回答
0

You can use:

ContentValues cv = new ContentValues();
cv.put(KEY1,value1);
cv.put(KEY2,value2);
//... all the fields you want to update
String where = KEY_CONTENT + " = " + value;
db.update(table_name,cv,where,null);

KEY1,KEY2 ... are the name of the fields you want to update value1,value2... are the new values of the fields you want to update the where String is to tell in which row you need to update.

于 2013-05-06T18:20:00.653 回答