在Android的SQLite的更新功能无法正常工作 [英] Update Function in android SQLite is not working

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

问题描述

在我的应用程序需要添加和编辑数据的SQLite数据库。当我做更新数据功能的应用程序不给任何错误,但我的数据库不会更新。这是我更新的功能。我在网上两天搜索,但不能使这个。请帮我。

In my application I need to add and edit data to the SQLite database. When I do update data function app do not give any errors but my database wont update. Here is my Update function. I search in the web for two days but couldn't make this. Please help me.

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;
}

在此先感谢!

Thanks in advance !!

推荐答案

有可能是在更新语句有问题,不妨试试:

There may be a problem in the update statement, Try:

 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

和是经过<一个href="http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#update%28java.lang.String,%20android.content.ContentValues,%20java.lang.String,%20java.lang.String%5B%5D%29">public INT更新(字符串表,ContentValues​​值,字符串whereClause,字符串[] whereArgs)功能。

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

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