0

一切正常,除了一件事。当我尝试提取得分最高的用户名时,程序失败。

我得到的结果是 0 而不是 le_user

这是行为怪异的代码部分:

string query = "SELECT * FROM \"Highscore_List\" ORDER BY Highscore_List.score DESC LIMIT 1";
DataTable  recipe = db.GetDataTable(query);
foreach (DataRow r in recipe.Rows)
{
    string old_user = r["user_name"].ToString();
    int oude_topscore = Convert.ToInt32(r["score"]);
}

而且分数是对的,只是用户名不对。当我离开这部分查询时

ORDER BY Highscore_List.score DESC LIMIT 1

结果还是一样。所以这不是问题。

那么我做错了什么?

编辑:

这是它的 SQL 转储:

-- ----------------------------
-- Table structure for "main"."Highscore_List"
-- ----------------------------
DROP TABLE "main"."Highscore_List";
CREATE TABLE "Highscore_List" (
"id"  INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"score"  INTEGER NOT NULL,
"user_name"  INTEGER NOT NULL
);

-- ----------------------------
-- Records of Highscore_List
-- ----------------------------
INSERT INTO "main"."Highscore_List" VALUES (1, 1, 'hui');
INSERT INTO "main"."Highscore_List" VALUES (2, 2, 'Onbekend');
INSERT INTO "main"."Highscore_List" VALUES (3, 3, 'onbekend_tt');
INSERT INTO "main"."Highscore_List" VALUES (4, 2, 'onbekenddd');
INSERT INTO "main"."Highscore_List" VALUES (5, 6, 'le_user');
INSERT INTO "main"."Highscore_List" VALUES (6, 0, 'Onbekend');
4

1 回答 1

1

You have created your column "user_name" as an integer column.

Actually, it is ok for SQLite to put text values into an integer column and read it out again as text. However, I'm not familiar with the ADO.NET interface to SQLite. It seems that it reads out "user_name" values as integer which results in the 0 values. I see two ways to solve the problem:

  1. Create the "user_name" column as TEXT
  2. Find a way to tell the ADO.NET-SQLite-bridge that it should interpret the values in the "user_name" column of query results as TEXT
于 2012-09-12T14:27:00.440 回答