I want to write a Query to delete a row from the table. I am confused of writing the statement. I need some help in writing this. I am providing my requirement here with plain sql statement.
我想编写一个查询来从表中删除一行。我写这个声明感到困惑。我写这篇文章需要一些帮助。我在这里提供了纯sql语句的需求。
(Pseudo code)
(伪代码)
delete from tablename where value =="string1" && value2 == "string2" && value3 == "string3";
I want to write this in the Sqlite syntax for android db.delete(tablename, whereclause, whereargs);
.
我想用Sqlite语法编写android db.delete(tablename, whereclause, whereargs);
I would be thankful for your help.
我要感谢你的帮助。
4 个解决方案
#1
28
a better way would be to use
更好的方法是使用
String where = "value1 = ?"
+ " AND value2 = ?"
+ " AND value3 = ?";
String[] whereArgs = {string1,string2,string3};
#2
15
String table_name = "myTable";
String where = "value1 = 'string1'"
+ " AND value2 = 'string2'"
+ " AND value3 = 'string3'";
String whereArgs = null;
mDb.delete(table_name, where, whereArgs);
#3
2
mdb.delete("tablename",new String("value1=? and Value2=? and value3=?"),new String[]{value1,value2,value3});
#4
1
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("DELETE FROM tablename WHERE value1='"+string1+"' AND value2='"+string2+"' AND value3='"+string3+"' "); //delete row in a table with the condition
db.close();
#1
28
a better way would be to use
更好的方法是使用
String where = "value1 = ?"
+ " AND value2 = ?"
+ " AND value3 = ?";
String[] whereArgs = {string1,string2,string3};
#2
15
String table_name = "myTable";
String where = "value1 = 'string1'"
+ " AND value2 = 'string2'"
+ " AND value3 = 'string3'";
String whereArgs = null;
mDb.delete(table_name, where, whereArgs);
#3
2
mdb.delete("tablename",new String("value1=? and Value2=? and value3=?"),new String[]{value1,value2,value3});
#4
1
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("DELETE FROM tablename WHERE value1='"+string1+"' AND value2='"+string2+"' AND value3='"+string3+"' "); //delete row in a table with the condition
db.close();