日期:2014-05-18 浏览次数:20854 次
private void button1_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("server= .\\SQLEXPRESS;uid=testuser1;pwd=test123;database=manage"); conn.Open(); SqlCommand cmd = new SqlCommand(); SqlTransaction sqltran = conn.BeginTransaction(); cmd.Connection = conn; cmd.Transaction = sqltran; try { for (int i = 0; i < 99999; i++) { cmd.CommandText ="UPDATE [newplan] SET [dept] = '" + i + "' WHERE [number]='11'"; cmd.ExecuteNonQuery(); txt_number.Text = i.ToString(); } sqltran.Commit(); } catch { sqltran.Rollback(); } finally { conn.Close(); }