Solved

Delete record(s) using a variable with Android SQLite

Posted on 2013-11-28
3
1,340 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
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
Manish earned 500 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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

821 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