android SQLite 中的更新功能不起作用

编程入门 行业动态 更新时间:2024-10-24 20:12:50
本文介绍了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; }

提前致谢!!

推荐答案

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

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

是的,通过 public int update (String table, ContentValues values, String whereClause, String[] whereArgs) 函数.

更多推荐

android SQLite 中的更新功能不起作用

本文发布于:2023-10-31 04:07:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544952.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   功能   android   SQLite

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!