Android SQLite 问题,未找到列

发布于 2024-11-01 18:23:27 字数 1674 浏览 1 评论 0原文

我正在工作应用程序的民意调查部分,但我不断收到异常,说在将值插入数据库时​​找不到我的答案 2。

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 tblPoll 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;");

这是我将项目插入行的代码,它适用于每个答案(团队成员),但皮特除外。我把皮特放在第一位、最后一位、第二位,而他是唯一打破这一规定的人。

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);";

这是我用来制作表格的插入代码。

任何帮助将不胜感激。

@2red13 我像你一样运行了它(所有字段都正确填写,但在 Answer2 上仍然混乱。

新代码:

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'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 tblPoll 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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

东北女汉子 2024-11-08 18:23:27

我没有任何 Peet schoud 失败的想法,但是你执行更新的方式有点慢,尝试:

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

也许它也解决了 Peet 问题 ^^

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 ^^

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文