mardi 3 février 2015

Use SQLite INSERT code with a string in android

I try to insert all listview items' name to a sqlite databace but I don't know how to do that. I guess this loop could help me but faced error in 6th line:



final SQLiteDatabase db = openOrCreateDatabase("LMDB", MODE_PRIVATE,null);
db.execSQL("CREATE TABLE IF NOT EXISTS MyTable (id INT primary key autoincrement, onvan VARCHAR , ahamiyat INT, foriyat INT, olaviyat INT);");
String temp ="";
for(int i=0;i<myList.getAdapter().getCount();i++)
{
temp = MyListAdapter.getItemTitle(i);
db.execSQL("INSERT INTO MyTable VALUES ('"+temp+"')");
}
db.close();


2nd Question:


when I delete a line from database is that "id INT primary key autoincrement" rearrange ids? (for example -1 rest of ids)


Thanks


Aucun commentaire:

Enregistrer un commentaire