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 ?
Danimal-KAsked:
Who is Participating?
 
ManishConnect With a Mentor LeadCommented:
Try this
String firstName = "Bill";
String columnName="name";

db.delete("mytable", columnName+"="+firstName, null);
0
 
ManishLeadCommented:
or check this
db.delete("mytable", columnName+"=? ", new String[] { firstName });
0
 
Danimal-KAuthor Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.