mardi 17 février 2015

sqlite update on fresh inserted Data fails in android

I have tried to make a shopping basket. I've inserted some items into the basket Table but when i try to update my frsh inserted data nothing happens :( After restarting my App i can update the count as much as i want.


I hope somebody can help me



private SQLiteDatabase myDB = null;
public void addWarenkorb(Produkt prod, MainActivity mainActivity)
{
try
{
myDB = mainActivity.openOrCreateDatabase(DB_NAME, Context.MODE_PRIVATE, null);
/* ContentValues insert = new ContentValues();
insert.put("produkt_id",prod.getId());
insert.put("count",prod.getCount());*/
myDB.beginTransaction();
// myDB.insertOrThrow("warenkorb", null, insert);
myDB.execSQL("INSERT INTO warenkorb (produkt_id, count) VALUES("+prod.getId()+", "+prod.getCount()+");");
myDB.setTransactionSuccessful();
myDB.endTransaction();
myDB.close();
}
catch(Exception e)
{

System.out.println("saveDB: "+e);
}
finally
{
if(myDB !=null)
myDB.close();
}
}

public void newCount(Integer value, int position, MainActivity mainActivity)
{
try{
myDB = mainActivity.openOrCreateDatabase(DB_NAME, Context.MODE_PRIVATE, null);
myDB.beginTransaction();
myDB.execSQL("UPDATE warenkorb SET Count="+value+" WHERE id="+position);
myDB.setTransactionSuccessful();
myDB.endTransaction();
myDB.close();
}
catch(Exception e)
{
System.out.println("getProduktID: "+e);
}
finally
{
if(myDB !=null)
myDB.close();
}
}

Aucun commentaire:

Enregistrer un commentaire