更新不在SQLite数据库中

时间:2013-03-14 06:34:34

标签: android database sqlite

我有一段代码,当点击List Item时会更新我表格中的一行。   这是代码,

    list_replace.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> Parent,View v, int Position, long id) {

            ContentValues cvs = new ContentValues();

           cvs.put(COLUMN_NAME_READING_MODE, ReadingMode);
           cvs.put(COLUMN_NAME_PASTDATETIME, StartDate);
           cvs.put("EndDateTime", CurrentDateTime);
           cvs.put(COLUMN_NAME_READINGVALUE,Reading);
           DB.update(TABLE_NAME, cvs, "_Id =" + id, null);

          DB.close();

        }
    });

但我没有在表格中看到任何记录更新。请纠正我。

任何帮助都会得到赞赏。

1 个答案:

答案 0 :(得分:1)

list_replace.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> Parent,View v, int Position, long id) {

        ContentValues cvs = new ContentValues();

       cvs.put(COLUMN_NAME_READING_MODE, ReadingMode);
       cvs.put(COLUMN_NAME_PASTDATETIME, StartDate);
       cvs.put("EndDateTime", CurrentDateTime);
       cvs.put(COLUMN_NAME_READINGVALUE,Reading);
       SQLiteDatabase db = context.openOrCreateDatabase(DATABASE_NAME,
            Context.MODE_PRIVATE, null);   // add this line
       db.update(TABLE_NAME, cvs, "_Id =" + id, null);

       db.close();

    }
});
相关问题