public void test2(String[] users)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (var myTransaction = myDB.BeginTransaction())
{
using (cmd = myDB.CreateCommand())
{
cmd.Transaction = myTransaction;
cmd.CommandText = "UPDATE myTable SET counter = counter + 1 WHERE user = @user";
cmd.Parameters.AddWithValue("@user", "");
foreach (string person in users)
{
cmd.Parameters["@user"].Value = person;
cmd.ExecuteNonQuery();
}
}
myTransaction.Commit();
stopwatch.Stop();
Console.WriteLine("Updating existing users took: " + stopwatch.Elapsed);
}
}
我很想弄清楚这个问题。我查看了大量的 c# 事务示例,我的代码看起来与所有这些示例都非常相似,除了具有 foreach 循环。但是我在一个事务中看到了多个 ExecCuteNonQuery,所以我不知道问题是什么。有什么帮助吗?
编辑:猜猜我应该解释这个问题:P
得到:
"System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'SQLiteCommand'."
上cmd.Parameters["@user"].Value = person;
线。