reijin
reijin

Reputation: 121

Updating values in a table: SQLite error. Insufficient parameters supplied to the command

Yeah! its me again - seems like I have to ask you very often these days...

My Problem this time: I created a SQLite command to update some (not all) values in my table. Here is my code:

using (SQLiteConnection con = new SQLiteConnection(string.Format("Data Source={0};Version=3;", mstrDatabase)))
{
    try
    {
        using (SQLiteCommand com = new SQLiteCommand("update WDATEN set TS_OUT = @TS_OUT, DATA_OUT = @DATA_OUT where ID = @ID", con))
        {
            com.Parameters.AddRange(new SQLiteParameter[] 
            {
                new SQLiteParameter("TS_OUT", DbType.DateTime){ Value = date},
                new SQLiteParameter("DATA_OUT", DbType.Double){ Value = numRest.Value}
            });
            con.Open();
            com.ExecuteNonQuery();
            mDa.Fill(dsWDaten.WDATEN);
            con.Close();
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show("Beim Speichern des Datensatzes ist ein Fehler aufgetreten.\n" + ex.ToString(), "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}

Sadly every time I execute this code block - I get the exception:

SQLite error. Insufficient parameters supplied to the command.

Searching here and on other pages didn't help me. What am I missing?

Upvotes: 1

Views: 2927

Answers (2)

Tim
Tim

Reputation: 15247

Your query has three parameters (@TS_OUT, @DATA_OUT and @ID) but you're only supplying parameters for the first two, not for @ID.

Upvotes: 4

Larry Lustig
Larry Lustig

Reputation: 50998

I do not see where you set the parameter @ID in your code. Your SQL statement contains three parameters, you supply values for only two.

Upvotes: 2

Related Questions