title: Indexing a datatable
body: <p>I have a <code>Datatable</code> which contains millions of data.</p>
  
  <p><strong>DATATABLE : Before creating Index</strong></p>
  
  <pre><code>x--------------------------------x
  |     DateColumn        |  Name  |
  x-----------------------|--------x
  | 2014-01-02 10:01:03   |    A   | 
  | 2014-01-02 11:07:23   |    A   |
  | 2014-01-03 07:12:15   |    A   |
  | 2014-01-15 11:01:03   |    B   |
  | 2014-01-16 13:17:23   |    B   |
  | 2014-01-16 22:22:15   |    B   |
  |          .            |    .   |
  |          .            |    .   |
  |          .            |    .   |
  x-----------------------|--------x
  </code></pre>
  
  <p>When I query from the above table for a particular <code>Name</code>, it takes almost 7 seconds to retrieve records using <code>datatable.Select</code>.</p>
  
  <pre><code>foreach(DataRow dr in datatable1.Select("Name='C'"))
  {
  
  }
  </code></pre>
  
  <p>I searched a lot and found that creating a column with <code>AutoIncrement</code> and sorting that column with a <code>DataView</code> will improve performance. Here is the code I tried.</p>
  
  <pre><code>datatable1.Columns["Id"].AutoIncrement = true;
  datatable1.Columns["Id"].AutoIncrementSeed = 1;
  ReadFromCSV(); // Method thatread from CSV file and inserts to datatable1.    
  DataView dv = new DataView(datatable1);
  dv.Sort = "Id ASC";
  datatable1= dv.ToTable(); 
  </code></pre>
  
  <p>Now it takes only 4 seconds to retrieve records using <code>datatable.Select</code>. Now my question is : <br><br> <strong><code>IS THERE A WAY TO CREATE NON-CLUSTERED INDEX FOR A COLUMN IN DATATABLE TO IMPROVE PERFORMANCE ADDITIONALLY?</code></strong></p>