Redgren Grumbholdt
Redgren Grumbholdt

Reputation: 1230

SQlite not updating records

I'm trying to update existing records in a table, here is the table:

enter image description here Here is my code:

using (SQLiteConnection c = new SQLiteConnection(ConnectionString))
{
    c.Open();
    using (SQLiteCommand cmd = new SQLiteCommand())
    {
        try
        {
            string _FINAL_SQL = "UPDATE act_monthly_listings SET loan = " + GRAND_LOAN_TOTAL + " AND interest = " + INTEREST + " AND contr = " + GRANT_CONTRIBUTIONS + " AND payment = " + GRAND_PAYMENTS_TOTAL + " WHERE act = " + act + " AND year = " + year + " AND month = " + month + ";";
            cmd.CommandText = _FINAL_SQL;
            Clipboard.SetText(_FINAL_SQL);
            cmd.Connection = c;
            cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            Clipboard.SetText(ex.ToString());
        }

    }
}

No error or exception is being thrown, but its not updating.

example sql:

UPDATE act_monthly_listings SET loan = 60 AND interest = 6 AND contr = 0 AND payment = 100 WHERE act = 93 AND year = 2014 AND month = 3;

I will be expecting to see the following record entry to be updated:

enter image description here

Upvotes: 0

Views: 1749

Answers (1)

Ludwik
Ludwik

Reputation: 101

Your query is incorrect, you cannot use "AND" keyword in SET part of query, you should use comma "," to separate fields that you want to update.

Please see documentation for correct UPDATE statement syntax: https://sqlite.org/lang_update.html

Your query should be:

UPDATE act_monthly_listings SET loan = 60, interest = 6, contr = 0, payment = 100 WHERE act = 93 AND year = 2014 AND month = 3;

Upvotes: 3

Related Questions