これは作成された私のテーブルです:
public void onCreate(SQLiteDatabase db) {
String insertNewFormDetails = "create table if not exists " + TABLE_NAME + " ( " + BaseColumns._ID + " integer primary key autoincrement, "
+ NAME + " text not null, "
+ SCHOOL + " text not null, "
+ CURRENTDATE + " text not null, "
+ FORMTYPE + " text not null);";
// Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.
db.execSQL(insertNewFormDetails);
}
これで、自動インクリメントを持つこの主キーができました。その列のコンテンツを実際に取得するにはどうすればよいですか?
UPDATE
クエリに対して今行っていること。
DBAddForm dbOpener2 = new DBAddForm(this);
SQLiteDatabase sqliteDatabase2 = dbOpener2.getReadableDatabase();
ContentValues contentValues2 = new ContentValues();
String selectQuery = "SELECT * FROM " + "FormDetails";
SQLiteDatabase db = dbOpener2.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
contentValues2.put("school",school);
sqliteDatabase2.update("FormDetails", contentValues2, cursor.getString(0) + " = " +primaryKey , null);
} while (cursor.moveToNext());
}
ただし、現在は、最初の列のすべての行を更新しています。と等しい場合にのみ行を更新したかったのprimaryKey
です。アドバイスしてください?ありがとう!私はすべての試みと本当に混乱しました。