SQlite不更新记录

问题描述 投票:0回答:1

我正在尝试更新表中的现有记录,这是表:

enter image description here这是我的代码:

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());
        }

    }
}

没有抛出错误或异常,但它没有更新。

示例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;

我期待看到以下记录条目更新:

enter image description here

c# .net sqlite sql-update executenonquery
1个回答
3
投票

您的查询不正确,您不能在查询的SET部分使用“AND”关键字,您应该使用逗号“,”来分隔您要更新的字段。

有关正确的UPDATE语句语法,请参阅文档:https://sqlite.org/lang_update.html

您的查询应该是:

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

© www.soinside.com 2019 - 2024. All rights reserved.