title: Accelerate very time consuming method for DataTable
body: <p>I am working on a solution where I have a very time consuming method (GetArbeitsplaene) and I have no idea to accelerate  it. I have a SQL 2008 R2 Express Edition DB for my data. In one table I have 100.000 entries. Here my code:</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Gets the arbeitsplaene.
  /// &lt;/summary&gt;
  private void GetArbeitsplaene()
  {
      DataColumn col = new DataColumn("Arbeitsplan", typeof(List&lt;Arbeitsplan&gt;));
      dTable.Columns.Add(col);
  
      for (int i = 0; i &lt; dTable.Rows.Count; i++)
      {
          DataRow row = dTable.Rows[i];
          string materialnummer = Convert.ToString(row[1]);
  
          if (arbeitsplaeneTable == null)
          {
              SQLHelperClass.CreateTable(cn, "ARBEITSPLAENE", ref arbeitsplaeneTable);
          }
  
          DataRow[] select = arbeitsplaeneTable.Select("Material Like '" + materialnummer + "'");
          List&lt;Arbeitsplan&gt; list = Converter.ConvertDataRowToArbeitsplaene(select);
  
          dTable.Rows[i].SetField("Arbeitsplan", list);
      }
  
      // very important, otherwise the changes of the images will be tracked.
      dTable.AcceptChanges();
  }
  
  /// &lt;summary&gt;
  /// Converts the data row to arbeitsplaene.
  /// &lt;/summary&gt;
  /// &lt;param name="select"&gt;The select.&lt;/param&gt;
  /// &lt;returns&gt;&lt;/returns&gt;
  public static List&lt;Arbeitsplan&gt; ConvertDataRowToArbeitsplaene(DataRow[] select)
  {
      List&lt;Arbeitsplan&gt; list = new List&lt;Arbeitsplan&gt;();
  
      for (int i = 0; i &lt; select.Count(); i++)
      {
          Arbeitsplan plan = new Arbeitsplan();
          DataRow row = select[i];
          plan.Material = Convert.ToString(row[0]);
          plan.Vrg = Convert.ToString(row[1]);
          plan.Steu = Convert.ToString(row[2]);
          plan.Kurztext_Vorgang = Convert.ToString(row[3]);
          plan.Arbeitsplatz = Convert.ToString(row[4]);
          plan.LstArt = Convert.ToString(row[5]);
          plan.Kostenstelle = Convert.ToString(row[6]);
          list.Add(plan);
      }
  
      return list;
  }
  
      /// &lt;summary&gt;
      /// Creates the table.
      /// &lt;/summary&gt;
      /// &lt;param name="tableName"&gt;Name of the table.&lt;/param&gt;
      /// &lt;param name="table"&gt;The table.&lt;/param&gt;
      public static void CreateTable(SqlConnection cn, string tableName, ref DataTable table)
      {
          string sql = "select * from " + tableName;
          SqlCommand cmd = new SqlCommand(sql, cn);
          SqlDataAdapter tempAdapter = new SqlDataAdapter(cmd);
          SqlCommandBuilder tempcb = new SqlCommandBuilder();
          tempcb.ConflictOption = ConflictOption.OverwriteChanges;
          tempcb.DataAdapter = tempAdapter;
          table = new DataTable();
          tempAdapter.Fill(table);
      }
  </code></pre>
  
  <p>So I need to run the for loop 100.000 times and this takes time. How can I improve my code to be faster? </p>
  
  <p>Thanks,
  TRO</p>