title: Loop inside a transaction in C#
body: <p>I have a method in C# that executes some queries to insert in the data base inside a transaction.</p>
  
  <p>What I want to do is a loop to insert several "Phone Numbers"</p>
  
  <pre><code>// Creates the transaction
  dbTransaction = dbConnection.DbConnection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
  
  // Creates the sql command
  dbCommand = factory.CreateCommand();
  dbCommand.Connection = dbConnection.DbConnection;
  dbCommand.Transaction = dbTransaction;    
  </code></pre>
  
  <p>... logic stuff</p>
  
  <pre><code>// Inserts the phone
  foreach (PlacePhoneDTO placePhoneDTO in placePhoneList)
  {
      dbCommand.CommandText = sqlStatementPhone.ToString();
      // Adds the parameters
      AddParameter&lt;int&gt;("@PlaceID", placeID, ref dbCommand);
      AddParameter&lt;string&gt;("@PhoneNumber", placePhoneDTO.phoneNumber, ref dbCommand);
      dbCommand.ExecuteNonQuery();
  }
  
  dbTransaction.Commit();
  </code></pre>
  
  <p>The second time that executes the loop fails</p>
  
  <p>Thanks a lot</p>