0

私はAndroidが初めてです。SQLite を使用して最初のアプリケーションでテーブルを更新しようとしています。しかし、SQLite Manager からテーブルを見ると、テーブルが更新されていないことがわかりました。問題がどこにあるのかわかりませんでしたか?

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);

    }
4

1 に答える 1

1
cursor.getColumnIndex(C_ID);

クエリの C_ID 列の列インデックスを返します。クエリには 1 列しかないため、0 です。

この列の値が必要な場合は、呼び出す必要がありますgetInt(index)(詳細については、 getColumnIndexを参照してください)。

于 2012-12-21T09:55:17.813 に答える