SQlite不更新记录
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQlite不更新记录相关的知识,希望对你有一定的参考价值。
我正在尝试更新表中的现有记录,这是表:
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;
我期待看到以下记录条目更新:
答案
您的查询不正确,您不能在查询的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;
以上是关于SQlite不更新记录的主要内容,如果未能解决你的问题,请参考以下文章
如何在不重新启动活动的情况下更新 recyclerview(来自 sqlite 的数据)
Android SQLite 更新行不起作用并且没有显示错误
Enmap (better-sqlite map) 在应用程序重新启动之前不会更新