Android SQL 删除行不起作用
首先,我在助手类中创建一个数据库,如下所示:
public void onCreate(SQLiteDatabase db) {
String sql = "create table " + TABLE + "( " + ID
+ " integer primary key autoincrement, " + FIELD1 + " text, "
+ FIELD2 + " text);";
Log.d("EventsData", "onCreate: " + sql);
db.execSQL(sql);
}// Where public static final String ID = "_id"; ect.
然后我插入了数据,并且我看到它通过在 TextView 中显示插入的数据来工作。当我需要删除一行时,我的问题就出现了。
我可以使用
db.delete(TABLE, null , null); 删除所有内容(我再次看到这有效)
但是,如果我将其更改为删除单行,例如
db. delete(TABLE, "_id" + Index, null); 其中,例如 int Index =4;
什么也没发生,我没有收到任何错误,也没有删除。
任何人都可以帮忙解释为什么会发生这种情况吗?
Firstly I am creating a Database in a helper class as follows:
public void onCreate(SQLiteDatabase db) {
String sql = "create table " + TABLE + "( " + ID
+ " integer primary key autoincrement, " + FIELD1 + " text, "
+ FIELD2 + " text);";
Log.d("EventsData", "onCreate: " + sql);
db.execSQL(sql);
}// Where public static final String ID = "_id"; ect.
I have then inserted data and I have seen it works by displaying the inserted data in a TextView. My problems come when I need to delete a row.
I can deleted everything by using
db.delete(TABLE, null , null);
(again I can see that this works)
However if I change it to deleted a single row such as
db.delete(TABLE, "_id" + Index, null);
Where for example int Index =4;
nothing happens, I get no errors and no delete.
Can anyone help with why this happens?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试
Try
db.delete(TABLE, "_id=" + Index, null);
db.delete(TABLE, "_id=" + Index, null);