Android SQLite更新行不工作 [英] Android SQLite update row not working

查看:202
本文介绍了Android SQLite更新行不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更新我的SQLite数据库中的一行。我的数据库助手类中的更新行方法如下

I am trying to update a row in my SQLite database. The update row method in my Database Helper class is as follows

public long updateNote(long rowId, String title, String body) {
    ContentValues args = new ContentValues();
    args.put(KEY_TITLE, title);
    args.put(KEY_BODY, body);

    return mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" +  rowId,
            null);
}

并且该行更新如下:

     mDbHelper.open();
     mDbHelper.updateNote(mRowId, title, body);
     mDbHelper.close();

但是当我检索行时,数据与以前完全相同。我已经搜索了SO,但我找不到任何答案。数据在如下所示的游标中返回:

But when I retrieve the rows, the data is exactly the same as before. I've searched SO already but I couldn't find any answers. The data is retrived in a cursor like this:

public Cursor fetchAllNotes() {
    return mDb.query(DATABASE_TABLE,
            new String[] { KEY_ROWID, KEY_TITLE, KEY_BODY, "link", "type",
                    KEY_DATE, KEY_TIME, KEY_DAY, KEY_YEAR }, null, null,
            null, null, null);

}


推荐答案

方法如下:

public long updateNote(long rowId, String title, String body) {
    ContentValues args = new ContentValues();
    args.put(KEY_TITLE, title);
    args.put(KEY_BODY, body);

    return mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=?",
            new String[]{rowId+""});
}

希望这个有效。

这篇关于Android SQLite更新行不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆