在我的应用程序中,我需要添加和编辑数据到SQLite数据库。当我更新数据功能的应用程序不要给任何错误,但我的数据库不会更新。这是我的更新功能。我在网上搜索了两天,但无法做到这一点。请帮帮我。Android SQLite中的更新函数不起作用
public long updateEvent(String id, String title, String description, String reminder, String alarm, Date date) {
try {
int rowid = Integer.parseInt(id);
Log.i("com.eventmanager", "insert Event");
formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String datestring = formatter.format(date);
ContentValues cv = new ContentValues();
cv.put(KEY_TITLE, title);
cv.put(KEY_DESCRIPTION, description);
cv.put(KEY_REMINDER, reminder);
cv.put(KEY_ALARM, alarm);
cv.put(KEY_DATE, datestring);
myDB.beginTransaction();
Log.i("com.eventmanager","SQL UPDATE ");
myDB.update(DATABASE_TABLE, cv, KEY_ROWID + "=" + rowid, null);
myDB.setTransactionSuccessful();
myDB.endTransaction();
} catch (Exception e) {
e.printStackTrace();
}
return 1;
}
在此先感谢!
只是'长I = myDB.update(DATABASE_TABLE,CV,KEY_ROWID + “=” + ROWID,NULL);'和打印'i'值在控制台中。检查并让我们知道我实际上打印了什么? –
它给出0;我的代码中是否有任何错误。我找不到它。 – Chrishan
也许你的交易造成了这种情况,尝试没有它们! – Carnal