title: C# Should I place the Sql/OleDb transaction.Commit() outside of a for loop?
body: <p>I have the following basic oledb loop:</p>
  
  <pre><code>using (OleDbConnection conn = new OleDbConnection(Con))
  {
      using (OleDbCommand cmd = new OleDbCommand())
      {
          for loop 
          {
          cmd.Connection = conn;
          conn.Open();
          transaction = conn.BeginTransaction(IsolationLevel.ReadCommitted);
          cmd.CommandText = "row by row insert"
          cmd.Some parameters, then ExecuteNonQuery
          transaction.Commit();
          }
      }
  }
  </code></pre>
  
  <p>However, I'm not certain if I should be placing the <code>Commit</code> within the loop after the command execution. Should I place it after all is said and done? Outlining the <code>using</code> would be a <code>try catch</code> containing a rollback in the <code>catch</code>. So I'm guessing if I want to be able to rollback all of my changes, I will want the loop to run completely, and then commit it?</p>
  
  <p>I also just learned about <code>TransactionScope</code>s which outline the SQL context in a using, so I'd like to know how it applies to that as well.</p>