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=> data.Field<String>("slideNo")=="5");
var w = sqlData.AsEnumerable().Where(data => data.Field<String>("slideNo") == "5")
.Select(data => data.Field<String>("QuestionStartText")).Distinct();
List<String> queryResult = new List<String>();
foreach (var item in w.ToArray<string>())
{
if (item != null)
{
String queryString = item;
//queryResult.Clear();
for (int i = 0; i < excelDataTable.Columns.Count; i++)
{
for (int k = 2; k < excelDataTable.Rows.Count; k++)
{
String row = "";
bool check = excelDataTable.Rows[k][0].ToString().StartsWith(queryString);
if (check)
{
for (int j = 0; j < excelDataTable.Columns.Count; j++)
{
string value = excelDataTable.Rows[k][j].ToString()+":";
row += value;
}
if (!queryResult.Contains(row))
{
queryResult.Add(row);
}
}
}
}
}
}
row
? \$\endgroup\$w
and how many cells inexcelDataTable
? \$\endgroup\$