Reputation: 1106
I want to write a Query to delete a row from the table. I have confused of writing the statement. I need some help in revising this.
db.delete(TABLE_NAME, "_id="+id, null);
I get my id from editText then put it into String id. This is the way to get my id:
String id = editId.getText().toString();
If there's not enough information to make you understand my problem, please tell me. I will add lacking parts.
I have find many data but I still cannot revise it. I would be thankful for your help.
This is my onCreate function:
public void onCreate(SQLiteDatabase db) {
final String INIT_TABLE = "CREATE TABLE " + TABLE_NAME + " (" +
_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
NAME + " CHAR, " +
TEL + " CHAR, " +
EMAIL + " CHAR);";
db.execSQL(INIT_TABLE);
}
Upvotes: 1
Views: 262
Reputation: 1704
public void delete_byID(int id){
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_NAME, KEY_ID+"="+id, null);
}
Upvotes: 0
Reputation: 27659
It looks fine to me see the syntax below:
String table = "TableName";
String where = "ColumnNumeric = 100"
+ " AND ColumnString = 'value2'";
String whereArgs = null;
mDb.delete(table, where, whereArgs);
Upvotes: 0
Reputation: 1710
As you said "I want to write a Query to delete a row from the table."
private void deleteRow(int id)
{
try
{
db.execSQL("delete from tablename where tablefield=" +id);
}
catch(Exception e)
{
e.printStackTrace();
}
}
you can call this function and pass id in it to delete row.
Upvotes: 1