database - Passing an SQLiteDatabase delete function a table name as a String in Android -
if run:
void deletetablerecords() { sqlitedatabase db = this.getwritabledatabase(); db.delete(table_albums,null,null); db.close(); }
i intended result. however, if run:
void deletetablerecords(string tablename) { sqlitedatabase db = this.getwritabledatabase(); db.delete(tablename,null,null); db.close(); }
with call of deletetablerecords("table_albums")
crash , told that:
android.database.sqlite.sqliteexception: no such table: table_albums
what should passing table name if not string?
table_albums
name of variable. value else.
i guess assigned value table_albums
, example:
private static final string table_albums = "somevalue";
in case need pass actual value, not name of variable:
deletetablerecords("somevalue");
a better approach make public constant:
public class dbhelper { public static final string table_albums = "somevalue"; // ... }
so can access in static way:
deletetablerecords(dbhelper.table_albums);
Comments
Post a Comment