Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delete record(s) using a variable with Android SQLite

Posted on 2013-11-28
3
Medium Priority
?
1,394 Views
Last Modified: 2013-11-29
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 ?
0
Comment
Question by:Danimal-K
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
Manish earned 2000 total points
ID: 39684716
Try this
String firstName = "Bill";
String columnName="name";

db.delete("mytable", columnName+"="+firstName, null);
0
 
LVL 11

Expert Comment

by:Manish
ID: 39684725
or check this
db.delete("mytable", columnName+"=? ", new String[] { firstName });
0
 

Author Comment

by:Danimal-K
ID: 39685492
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is a lot to be said for protecting yourself and your accounts with 2 factor authentication.  I found to my own chagrin, that there is a big downside as well.
Ransomware, the malware that locks down its victim’s files until they pay up, has always been a frustrating issue to deal with. However, a recent mobile ransomware will make the issue a little more personal… by sharing the victim’s mobile browsing h…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question