[英]Update Function in android SQLite is not working
在我的應用程序中,我需要向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;
}
提前致謝 !!
更新語句中可能存在問題,請嘗試:
long i = myDB.update(DATABASE_TABLE, cv, KEY_ROWID + "=?", new String[]{rowid});
if(i>0)
return 1; // 1 for successful
else
return 0; // 0 for unsuccessful
並且是通過public int update(String表,ContentValues值,String whereClause,String [] whereArgs)函數。
你的函數返回1; 那不行......它應該返回ContentValues cv
return db.update(DATABASE_TABLE, cv, KEY_ROWID+"="+rowId, null)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.