开发者

Android SQLite issue, column not found

开发者 https://www.devze.com 2023-02-24 22:00 出处:网络
I\'m working a poll portion of an app for work and I keep getting an exception saying that my answer 2 is not found when inserting values into the database.

I'm working a poll portion of an app for work and I keep getting an exception saying that my answer 2 is not found when inserting values into the database.

db.execSQL("UPDATE tblPoll SET Question='Who is more awesome?' WHERE rowid=1;");
    db.execSQL("UPDATE tblPoll SET Answer1='Dan' WHERE rowid=1;");
    db.execSQL("UPDATE tblPoll SET Answer2='Peet' WHERE rowid=1;");
    db.execSQL("UPDATE tblPo开发者_如何转开发ll SET Answer3='Jordan' WHERE rowid=1;");
    db.execSQL("UPDATE tblPoll SET Answer4='Spencer' WHERE rowid=1;");
    db.execSQL("UPDATE tblPoll SET result1=0 WHERE rowid=1;");
    db.execSQL("UPDATE tblPoll SET result2=0 WHERE rowid=1;");
    db.execSQL("UPDATE tblPoll SET result3=0 WHERE rowid=1;");
    db.execSQL("UPDATE tblPoll SET result4=0 WHERE rowid=1;");
    db.execSQL("UPDATE tblPoll SET resultTotal=0 WHERE rowid=1;");

This is my code to insert the items into the row, and it works for each of the answers(the members of the team), except for Peet. I've put Peet first, last, and as the second one, and he is the only one that breaks it.

private static final String DATABASE_CREATE =
    "CREATE TABLE tblPoll (id INTEGER PRIMARY KEY, " +
    "Question TEXT, Answer1 TEXT, Result1 NUMERIC, " +
    "Answer2 TEXT, Result2 NUMERIC, Answer3 TEXT, " +
    "Result3 NUMERIC, Answer4 TEXT, Result4 NUMERIC, " +
    "ResultTotal NUMERIC);";

This is my insert code to make the table.

Any help will be greatly appreciated.

@2red13 I ran it like you had(with all the fields filled out properly, and it is still messing up on Answer2.

New code:

ContentValues werte = new ContentValues();  
    werte.put("Answer1", "Dan");
    werte.put("Answer2", "Peet");
    werte.put("Answer3", "Jordan");
    werte.put("Answer4", "Spencer");
    werte.put("Result1", 0);
    werte.put("Result2", 0);
    werte.put("Result3", 0);
    werte.put("Result4", 0);
    werte.put("ResultTotal", 0);
    db.update("tblPoll", werte,"rowid=1",null);


I havn't any Idea whi Peet schoud fail, but the way you perform the updates is alittle bit slow, try:

ContentValues werte = new ContentValues();  
werte.put("Answer1", "Dan");
....
werte.put("resultTotal", 0);
db.update("tblPoll", werte,"rowid=1",null);

Maybe it solves the Peet Problem too ^^

0

精彩评论

暂无评论...
验证码 换一张
取 消