title: C# DbCommand in a loop
body: <p>I have a collection of files, for each file I am going to call an SP using Dbcommand in a transaction. </p>
  
  <p>for example:</p>
  
  <pre><code>  DbCommand insert = db.GetStoredProcCommand("Insert");
    db.AddInParameter(insert, "FileName", System.Data.DbType.String, 
        ID + ".xml");
    db.ExecuteNonQuery(insert, transaction); 
  </code></pre>
  
  <p>My question is how do I put this in a loop?</p>
  
  <p>The answer below doesn't work, but thanks for the otherwise great code sample. Problem is db doesn't have a Parameters collection that you can manipulate. check...</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/microsoft.practices.enterpriselibrary.data.sql.sqldatabase_members%28BTS.10%29.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/microsoft.practices.enterpriselibrary.data.sql.sqldatabase_members%28BTS.10%29.aspx</a></p>
  
  <p>I am declaring my database like this:</p>
  
  <pre><code>SqlDatabase db = new SqlDatabase(this.ConnectionString );
  </code></pre>