我目前正在使用 C# 和 SQLite 编写代码。有一个错误正在抛出,指出数据库在消息框中被锁定两次。该查询适用于 SQLite DB 浏览器,但是,当它被放置在 C# 代码中时,它会引发错误。这是给我一个错误的代码:cmd.CommandText = "UPDATE customers SET Bill = Bill - "+textBox2.Text+" WHERE customers.CustomerID = " + textBox1.Text + ";";等号似乎有问题,算术过程可能有问题。完整代码: SQLiteConnection myconn = new SQLiteConnection(@"Data Source = C:\Users\chick\Newspaper.db"); SQLiteCommand cmd = myconn.CreateCommand(); cmd.CommandText = "UPDATE customers SET Bill = (Bill - "+textBox2.Text+") WHERE customers.CustomerID = " + textBox1.Text + ";"; myconn.Open(); try { cmd.ExecuteNonQuery(); MessageBox.Show("Succesfully Update"); } catch(Exception ex) { MessageBox.Show(ex.Message); }更新:将格式更改为using() {}但它仍然无法正常工作。程序崩溃新代码: using (SQLiteConnection myconn = new SQLiteConnection(@"Data Source = C:\Users\chick\Newspaper.db")) { var sql = "Update customers SET Bill = Bill - @pay WHERE customers.CustomerID = @cid;"; myconn.Open(); using (var cmd = new SQLiteCommand(sql, myconn)) { cmd.Parameters.AddWithValue("@cid", textBox1.Text); cmd.Parameters.AddWithValue("@pay", textBox2.Text); cmd.ExecuteNonQuery(); } }
- 2 回答
- 0 关注
- 255 浏览
添加回答
举报
0/150
提交
取消