I've just run a query from a WinForms app that updates 1 field for 2k records, but it'll usually be more. Only thing is the app just stops responding, it takes around 30 seconds to update 10 records and that's just not good enough. How am I screwing up?
The code
using (SqlConnection conx = GetConnection())
{
conx.Open();
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = conx;
int counter = 0;
foreach (DataRow row in mainResultsTable.Rows)
{
if(controlResult)
{
thisSerial = row[2].ToString();
col = "[someColumn]";
}
cmd.CommandText = "UPDATE SomeTable$ SET [ToBeUpdated] = '" + DateTime.Now.ToString() + "' WHERE SomeColumn ='" + thisSerial.ToString() + "'";
cmd.ExecuteNonQuery();
counter++;
if (counter == 10)
{
MessageBox.Show("10");
}
}
}
}
PS. The test isn't super-accurate, I waited for the Messagebox to pop up.
So what I finally did is create a temporary table on SQL Server, import that upload data and do it all in a batch, deleting the temp-table after the operation is done, is this advisable?