gpt4 book ai didi

android - 如何通过仅输入特定列的字符串值来删除 SQLite 数据库的整行?

转载 作者:行者123 更新时间:2023-11-30 00:19:16 25 4
gpt4 key购买 nike

我正在使用这个方法来查询这个字符串:

public void deletedata(){
p=srt.split(",");

DatabaseHandler dba=new DatabaseHandler(this);
for(String s:p) {
dba.removeSingleproduct(s);
}

数据库方法是:

public boolean removeSingleproduct(String name) {
SQLiteDatabase db = this.getWritableDatabase();

return db.delete(tablename, productinserted + "=" + name, null) > 0;
}

我想通过调用数据库只删除一行,因为插入的产品可以有两个相同的值。

请大家帮忙

最佳答案

Since you're deleting with a selectedValue String, add a single quote before and after the name

return db.delete(tablename, productinserted + " = '" + name + "'", null) > 0;

Or you can simplify your code.

public int removeSingleproduct(String name) {
return getWritableDatabase().delete(tablename, productinserted + " = ?", new String[] { name });
}

Return int - the number of rows affected if a whereClause is passed in, 0 otherwise. To remove all rows and get a count pass "1" as the whereClause.

关于android - 如何通过仅输入特定列的字符串值来删除 SQLite 数据库的整行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46614036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com