I am having
- a DataTable (columns are AccId and TerrName) which contains more than 2000 rows.
- a large csv file (columns are AccId and External_ID) containing more than 6 millions records.
Now, I need to match AccId and have to find its corresponding External_ID from the csv file.
Currently I am achieving it using below code:
DataTable tblATL = Util.GetTable("ATL", false);
tblATL.Columns.Add("External_ID");
DataTable tbl = Util.CsvToTable("TT.csv", true);
foreach (DataRow columnRow in tblATL.Rows)
{
var query = tbl.Rows.Cast<DataRow>().FirstOrDefault(x => x.Field<string>("AccId") == columnRow["AccId"].ToString());
if (query != null)
{
columnRow["External_ID"] = query.Field<string>("External_ID");
}
else
{
columnRow["External_ID"] = "New";
}
}
This code is working well but only problem is a performance issue, its taking very very long time to get the result.
Please help. How can I improve its performance, do you have any other approach?