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);
}
}
I'm having a beast of a time figuring this one out. I've looked at tons of c# transaction examples, and my code looks pretty similar to all of them except for having the foreach loop. But I've seen multiple ExeCuteNonQuery's in a single transaction, so I have no idea what the problem is. Any help?
Edit: Guess I should explain the problem :P
Getting:
"System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'SQLiteCommand'."
On the cmd.Parameters["@user"].Value = person;
line.