Search datatable faster I would like to make the search faster as it takes a long time to retrieve the data that I require. Is there a faster method to do this? I have written the code below to allow me to search through a data table and retrieve data, which currently is fully functional. It's the nested for loops which I am using and wondering if there is another method of completing the tasks that the for loops get?

 DataTable sqlData = GetConfiguration();

       // var q = sqlData.AsEnumerable().Where(data=&gt; data.Field&lt;String&gt;("slideNo")=="5");

        var w = sqlData.AsEnumerable().Where(data =&gt; data.Field&lt;String&gt;("slideNo") == "5")
            .Select(data =&gt; data.Field&lt;String&gt;("QuestionStartText")).Distinct();

        List&lt;String&gt; queryResult = new List&lt;String&gt;();
        foreach (var item in w.ToArray&lt;string&gt;())
        {
            if (item != null)
            {
                String queryString = item;
                //queryResult.Clear();
                for (int i = 0; i &lt; excelDataTable.Columns.Count; i++)
                {   
                    for (int k = 2; k &lt; excelDataTable.Rows.Count; k++)
                    {
                       String row = "";
                       bool check = excelDataTable.Rows[k][0].ToString().StartsWith(queryString);
                       if (check)
                       {
                           for (int j = 0; j &lt; excelDataTable.Columns.Count; j++)
                           {
                               string value = excelDataTable.Rows[k][j].ToString()+":";
                               row += value;
                           }
                           if (!queryResult.Contains(row))
                           {
                               queryResult.Add(row);
                           }
                       }
                    }
                }
            }               
        }
The most obvious problem is when there are large number of strings, string concatenation is inherently slow. Try using a StringBuilder instead, like this:

 DataTable sqlData = GetConfiguration();

       // var q = sqlData.AsEnumerable().Where(data=&gt; data.Field&lt;String&gt;("slideNo")=="5");

        var w = sqlData.AsEnumerable().Where(data =&gt; data.Field&lt;String&gt;("slideNo") == "5")
            .Select(data =&gt; data.Field&lt;String&gt;("QuestionStartText")).Distinct();

        List&lt;String&gt; queryResult = new List&lt;String&gt;();
        StringBuilder sb = new StringBuilder();
        foreach (var item in w.ToArray&lt;string&gt;())
        {
            if (item != null)
            {
                String queryString = item;
                //queryResult.Clear();
                for (int i = 0; i &lt; excelDataTable.Columns.Count; i++)
                {   
                    for (int k = 2; k &lt; excelDataTable.Rows.Count; k++)
                    {
                       sb.Clear();
                       bool check = excelDataTable.Rows[k][0].ToString().StartsWith(queryString);
                       if (check)
                       {
                           for (int j = 0; j &lt; excelDataTable.Columns.Count; j++)
                           {
                               sb.Append(excelDataTable.Rows[k][j].ToString());
                               sb.Append(':');
                           }
                           string row = sb.ToString();
                           if (!queryResult.Contains(row))
                           {
                               queryResult.Add(row);
                           }
                       }
                    }
                }
            }               
        }