0

在我的代码的某个地方,我这样做:

        contentValues = new ContentValues();

//      contentValues.put("_ID",BaseColumns._ID); // Not Working can someone explain what this is and how it's used BaseColumns._ID ?
        contentValues.put("_ID", null); // Not working, Everywhere they say to pass in a null value and Android will do it's magic ... 

        contentValues.put("_ID", "1")    // This works but has to be changed manually every time
        contentValues.put("login", username.getText().toString());
        contentValues.put("password", pwd.getText().toString());
        contentValues.put("type", type);

这是我的小架构:

public static final String CREATE_DATABASE = "CREATE TABLE "+
            TABLE +"(_ID INTEGER PRIMARY KEY AUTOINCREMENT, login VARCHAR(50) NOT NULL, password VARCHAR(50) NOT NULL, type CHAR(1) NOT NULL)";

有人说不要放AUTOINCREMENT,但是在其他一些网站你可以在代码中看到。我不知道该怎么办了。如何让 Android 选择下一个增量值?

4

1 回答 1

1

使用autoincrement将自动为插入数据库的任何新行分配一个 ID

当您将某些内容插入数据库时​​,您不需要以contentValues.put("_ID", null);任何方式调用甚至访问该列,它会自动完成

于 2013-07-25T01:17:33.110 回答