SQlite 不更新记录
SQlite not updating records
我正在尝试更新 table 中的现有记录,这里是 table:
这是我的代码:
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;
我正在尝试更新 table 中的现有记录,这里是 table:
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;