0

我在表中插入了两个字段,即 truck_id 和 employee_id。

很抱歉问这个问题。但由于我是android新手,请帮帮我。

public void insert(String[] employeeName,int[] truck_id){

    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues vals = new ContentValues();

    vals.put(COLUMN_TRUCKID, "CM-3456");
    vals.put(COLUMN_NAME,"Sachin");
    //vals.put(KEY_PIN, "12345");

    vals.put(COLUMN_TRUCKID, "HR-6788");
    vals.put(COLUMN_NAME,"Sameer");
    //vals.put(KEY_PIN, "54321");

    vals.put(COLUMN_ID, "AM-6123");
    vals.put(COLUMN_NAME,"Sahu");
    //vals.put(KEY_PIN, "3452");

    db.insert("Login", "John",
            vals);
    db.insert("Login", "Sameer",
            vals);

    db.execSQL(COLUMN_NAME);

    //myDataBase.close();
}
4

1 回答 1

0

ContentValues是 a Map,因此每个列名一次只能包含一个条目。因此,您需要在设置其值后分别插入每个项目。

vals.put(COLUMN_TRUCKID, "CM-3456");
vals.put(COLUMN_NAME,"Sachin");
db.insert("Login", null, vals);

vals.put(COLUMN_TRUCKID, "HR-6788");
vals.put(COLUMN_NAME,"Sameer");
db.insert("Login", null, vals);

删除这一行,否则会发生不好的事情:

db.execSQL(COLUMN_NAME);
于 2012-06-15T10:12:38.403 回答