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 ?
DB Dev ToolsDatabasesAndroid

Avatar of undefined
Last Comment
Danimal-K

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Manish

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Manish

or check this
db.delete("mytable", columnName+"=? ", new String[] { firstName });
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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck