Link to home
Start Free TrialLog in
Avatar of Danimal-K
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 ?
ASKER CERTIFIED SOLUTION
Avatar of Manish
Manish
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or check this
db.delete("mytable", columnName+"=? ", new String[] { firstName });
Avatar of Danimal-K
Danimal-K

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+"="+'"+firstName+"', null);

Now it works !!!!
Thank you so much Karanw