0

I have the following table:

enter image description here

The following code:

for (int i = 0; i < lines.Length; i = i + 6)
    {
        print(lines[i]);
        print(lines[i + 1]);
        print(lines[i + 2]);
        print(lines[i + 3]);
        print(lines[i + 4]);
        print(lines[i + 5]);
        print("+++++++++++++++++++++");

        if (lines[i] == "99999") break;


        IDbCommand dbcmd = dbconn.CreateCommand();                                                  //creates command on connection

        string sqlInsert = "INSERT INTO questions (lvl, question, answer1, answer2, answer3, answer4, regdate, nrqasked, timebased, language) VALUES (@lvl, @question, @answer1, @answer2, @answer3, @answer4, @regdate, @nrqasked, @timebased, @language);";   // creates insert statement on sql insert string

        SqliteCommand command = new SqliteCommand();                                //creates new sqlite command
        //dbcmd.Parameters.Add(new SqliteParameter("@id", idNr));
        idNr++; ;
        intNr = int.Parse(lines[i + 1]);
        dbcmd.Parameters.Add(new SqliteParameter("@lvi", lines[i + 1]));
        dbcmd.Parameters.Add(new SqliteParameter("@question", lines[i + 2]));
        dbcmd.Parameters.Add(new SqliteParameter("@answer1", lines[i + 3]));
        dbcmd.Parameters.Add(new SqliteParameter("@answer2", lines[i + 4]));
        dbcmd.Parameters.Add(new SqliteParameter("@answer3", lines[i + 5]));
        dbcmd.Parameters.Add(new SqliteParameter("@answer4", ""));
        string myDate = System.DateTime.Now.ToString("yyyy.MM.dd");
        dbcmd.Parameters.Add(new SqliteParameter("@regdate", myDate));
        dbcmd.Parameters.Add(new SqliteParameter("@nrqasked", 0));
        dbcmd.Parameters.Add(new SqliteParameter("@timebased", 0));
        dbcmd.Parameters.Add(new SqliteParameter("@language", "SE"));

        dbcmd.CommandText = sqlInsert;                                              // sets dbcmd.CommandText to be equal to the insert statement created above
        dbcmd.ExecuteNonQuery();
    }

I get:

SqliteException: SQLite error Insufficient parameters supplied to the command

As I have barely used SQLite I cannot figure out the problem. I have googled and tested different solution but not succeeded.

3
  • Typo in this line dbcmd.Parameters.Add(new SqliteParameter("@lvi", lines[i + 1])); ? Commented Feb 16, 2019 at 12:58
  • Thanks. Unbelivable stupid by me. Please add this as an answer so I can mark it. Commented Feb 16, 2019 at 13:34
  • Not stupid at all! Sometimes the best troubleshooting tool is another pair of eyes. Commented Feb 16, 2019 at 13:39

1 Answer 1

1

It looks like a typo in this line dbcmd.Parameters.Add(new SqliteParameter("@lvi", lines[i + 1]));. Did you mean @lvl?

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.