2013-07-25 43 views
0

某处在我的代码我这样做:让Android的选择下一个SQLITE _ID

 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选择下一个增量值?

回答

1

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

你并不需要调用contentValues.put("_ID", null);甚至以任何方式访问列,当你插入一些到数据库中,它是自动完成的

+0

*巴掌*好吧完美的工作...任何想法如何使用'BaseColumns._ID'? – hayonj