Zulqadar Idrishi

Zulqadar Idrishi

  • NA
  • 471
  • 71.3k

What can be most efficient way of filtering data in DataTable?

Jul 25 2020 4:14 AM
The performance is not good, taking so much time. How can I improve the performance of the following code that gives me the same result?
 
 
for (int i = 0; i < dsResult.Tables[0].Rows.Count; i++)
{
     DataTable dtFiltered = dtWorkExp.Clone();
     foreach (DataRow drr in dtWorkExp.Rows)
     {
          if (drr["UserId"].ToString() == dsResult.Tables[0].Rows[l]["Registration NO."].ToString())
          {
              dtFiltered.ImportRow(drr);
          }
      }
 
 
     DataTable dtFilteredAward= dtAwards.Clone();
     foreach (DataRow drr in dtAwards.Rows)
     {
          if (drr["UserId"].ToString() == dsResult.Tables[0].Rows[l]["Registration NO."].ToString())
          {
              dtFilteredAward.ImportRow(drr);
          }
      }
 
 
     DataTable dtFilteredOtherQual = dtOtherQual.Clone();
     foreach (DataRow drr in dtOtherQual.Rows)
     {
          if (drr["UserId"].ToString() == dsResult.Tables[0].Rows[l]["Registration NO."].ToString())
          {
               dtFilteredOtherQual.ImportRow(drr);
          }
      }
   
     //Do some operation with filtered Data Tables
}

Answers (1)