0

Everything works fine, except one thing. When i try to pull the username of the one with the highest score, the program fails.

The result that i get is 0 instead of le_user

This is the part of code that act's weird:

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

And the score is right, just the user name not. And when i leave this part of the query

ORDER BY Highscore_List.score DESC LIMIT 1

The result is still the same. So that isn't the problem.

So what am I doing wrong?

EDIT:

Here is an SQL dump of it:

-- ----------------------------
-- 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');
6
  • 1
    Then it would suggest that the data in your table isnt what you thought. Commented Sep 12, 2012 at 13:57
  • @BugFinder, i've updated the question, so you can see that the table is what i tink. And when i change the number of highscore, the number at the program will change to... Commented Sep 12, 2012 at 14:01
  • What does "And when i change the number of highscore, the number at the program will change to" mean? I dont understand that, are you updating highscore in your db? Commented Sep 12, 2012 at 14:03
  • Yup, i have navicat (prog to admin datases) and with that, i update the number to check if the program works... Commented Sep 12, 2012 at 14:04
  • OK, but does your code work before you change values? No chance the drop isnt working? Commented Sep 12, 2012 at 14:11

1 Answer 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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.