I have completed an application which gathers specific records and marks them as Collected
. As of now, the application runs perfectly and does exactly what I need it to, but the problem comes in when a large data set is reviewed. If I am pulling records for one day or even maybe a week, it runs at a decent pace, but once you get a month of data or more, it takes a fairly long amount of time.
DataTable ModelData = getModelData() // Returns all records to search.
...
EnumerableRowCollection<DataRow> modelRows = (from model in ModelData.AsEnumerable()
where (model.Field<object>(GeographicalKey) ?? (object)String.Empty).ToString() == GeographicCode
select model);
ModelResults = modelRows.Any() ? modelRows.CopyToDataTable() : ModelData.Clone();
for (int i = 0; i < ModelResults.Rows.Count; i++)
{
for (int j = 0; j < ModelData.Rows.Count - 1; j++)
{
if (ModelResults.Rows[i]["Request ID"].ToString() == ModelData.Rows[j]["Request ID"].ToString())
{
ModelData.Rows[j]["Collected"] = "1";
}
}
}
The only part that executes slowly would be the for
and the nested for
. Is there possibly a better way that I can code this? I can't imagine this is the optimal coding for data table update operations, but it might be. Is this a possibility in LINQ (I'm completely new to LINQ)? I think this is enough code to make sense of what I'm doing, but if more is needed just let me know and I can post it up as well.