0

I'm new in Android. I'm trying to update the table in my first Application using SQLite. But when ı looked to the table from SQLite Manager ı saw that the table didn't updated. I couldn't find where the problem is?

public void EntryHesapla(int yilsql, String aysql,int digerTaksitlersql,
            int digersql,int maasSelosql,int maasHilalsql,int digerGelirlersql,
            int toplamHarcamasql,int toplamGelirsql,int eldeKalansql) {
        ContentValues cv = new ContentValues();
        cv.put(C_YIL, yilsql);
        cv.put(C_AY, aysql);
        cv.put(C_DIGERTAKSITLER, digerTaksitlersql);
        cv.put(C_DIGER, digersql);
        cv.put(C_MAASSELO, maasSelosql);
        cv.put(C_MAASHILAL, maasHilalsql);
        cv.put(C_DIGERGELIRLER, digerGelirlersql);
        cv.put(C_TOPLAMHARCAMA, toplamHarcamasql);
        cv.put(C_TOPLAMGELIR, toplamGelirsql);
        cv.put(C_ELDEKALAN, eldeKalansql);

        String[] selectionArgs=new String[]{yilsql+"", aysql};
        String entryHesaplaSQL="SELECT c_id FROM harcamalar WHERE "+C_YIL+"= ? AND "+C_AY+"= ?";
        Cursor cursor=ourDatabase.rawQuery(entryHesaplaSQL, selectionArgs);
        cursor.moveToFirst();
        cursor.moveToPosition(cursor.getCount() - 1);
        int index=cursor.getInt(cursor.getColumnIndex(C_ID));
        if(index>=0)
                ourDatabase.update(DB_TABLE, cv, C_ID+"="+index, null);
        else ourDatabase.insert(DB_TABLE, null, cv);

    }
3
  • you should test the return value of update and insert Commented Dec 21, 2012 at 9:51
  • are u closing your database after insertion? Commented Dec 21, 2012 at 9:54
  • how will ı test return values? Commented Dec 21, 2012 at 10:10

1 Answer 1

1
cursor.getColumnIndex(C_ID);

returns the column index for the C_ID column in your query. It is 0, as there is only 1 column in your query.

If you want the value for this column, you need to call getInt(index) (see getColumnIndex for further details.)

Sign up to request clarification or add additional context in comments.

1 Comment

This is the perfect one. Its all on your query selection.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.