Danimal-K
asked on
Delete record(s) using a variable with Android SQLite
I can delete row(s) using known TEXT like 'Bill'
db.delete("mytable", "name = 'Bill'", null); ... this works
I want to delete row(s) from a table using a VARIABLE ... what is the syntax ?
The following 3 attempts do not work :
String FirstName = "Bill";
db.delete("mytable", "name = FirstName", null);
db.delete("mytable", "name = String.valueOf(FirstName)" , null);
db.delete("mytable", "name=?", FirstName);
Is there a SIMPLE solution ?
db.delete("mytable", "name = 'Bill'", null); ... this works
I want to delete row(s) from a table using a VARIABLE ... what is the syntax ?
The following 3 attempts do not work :
String FirstName = "Bill";
db.delete("mytable", "name = FirstName", null);
db.delete("mytable", "name = String.valueOf(FirstName)"
db.delete("mytable", "name=?", FirstName);
Is there a SIMPLE solution ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
String firstName = "Bill";
String columnName="name";
db.delete("mytable", columnName+"="+firstName, null);
firstName needs to be in single quotes so I tweeked the where statement
db.delete("mytable", columnName+"="+'"+firstNam e+"', null);
Now it works !!!!
Thank you so much Karanw
String columnName="name";
db.delete("mytable", columnName+"="+firstName, null);
firstName needs to be in single quotes so I tweeked the where statement
db.delete("mytable", columnName+"="+'"+firstNam
Now it works !!!!
Thank you so much Karanw
db.delete("mytable", columnName+"=? ", new String[] { firstName });