title: datatable loop performance
body: <p>I have a question about loop DataTable in C#</p>
  
  <p>I have a DataTable has about 20.000 rows and 60 columns</p>
  
  <p>I want to write a SQL query to insert all of data in DataTable to database</p>
  
  <p>I'm using My Sql</p>
  
  <p>this is my SQL syntax:</p>
  
  <pre><code>"Insert into a values (...), (...), (...), ..." 
  </code></pre>
  
  <p>"(...)" is all data in one row</p>
  
  <p>this is C# code: </p>
  
  <pre><code>DataTable myDataTable; // myDataTable has 20.000 rows and 60 columns
  string mySql = "insert into a values "
  for(int iRow = 0; iRow &lt; myDataTable.Rows.Count; iRow++)
  {
       mySql += "(";
       for(int iColumn = 0; iColumn &lt; myDataTable.Columns.Count; iColumn++)
       {
            string value = myDataTable.Rows[iRow][iColumn].ToString()
            string parameter = "@" + iRows.ToString() + iColumns.ToString();
            // here is some code for add "parameter" and "value" to MySqlCommand
            mySql += ","
       }
  
       // remove "," at the end of string mySql
       mySql  = mySql.SubString(0, mySql.Length - 1);
  
       mySql += "),"
  }
  // remove "," at the end of string mySql
  // after that, I will execute mySql command to insert data into database here
  </code></pre>
  
  <p>when I run that code, It is take a lots of time to finish</p>
  
  <p>I try change from "string" to "StringBuilder", but it is just faster a little.</p>
  
  <p>How can I make the code run faster? </p>
  
  <p>Thanks for all supports.</p>