我试图更新表格中的现有记录,这是表格:
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;
我希望看到以下记录条目更新:
答案 0 :(得分:3)
您的查询不正确,您无法使用" AND"在SET部分查询中的关键字,你应该使用逗号","分隔您要更新的字段。
请参阅文档以获取正确的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;