How to efficiently iterate in list of data and search data in another datatableSearch datatable fasterConverting List to a DataTable and/or DataSet Extension MethodsConvert datagridview data to DataTableList<List<string>> vs DataTableIterate over list and valid email addressAdd data to DataTableLeetcode 10: Regular Expression MatchingEfficiently track changes to a List<T>List of classes to datatableHandler for jQuery DataTable search with filters and pagination

What typically incentivizes a professor to change jobs to a lower ranking university?

How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?

Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?

Finding angle with pure Geometry.

Schoenfled Residua test shows proportionality hazard assumptions holds but Kaplan-Meier plots intersect

What is the word for reserving something for yourself before others do?

In Japanese, what’s the difference between “Tonari ni” (となりに) and “Tsugi” (つぎ)? When would you use one over the other?

Test whether all array elements are factors of a number

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

What's the output of a record cartridge playing an out-of-speed record

Watching something be written to a file live with tail

Test if tikzmark exists on same page

Have astronauts in space suits ever taken selfies? If so, how?

Mathematical cryptic clues

"You are your self first supporter", a more proper way to say it

Adding span tags within wp_list_pages list items

How to add double frame in tcolorbox?

The Clique vs. Independent Set Problem

Which models of the Boeing 737 are still in production?

Writing rule stating superpower from different root cause is bad writing

I'm planning on buying a laser printer but concerned about the life cycle of toner in the machine

Are the number of citations and number of published articles the most important criteria for a tenure promotion?

What does it mean to describe someone as a butt steak?

Is it possible to do 50 km distance without any previous training?



How to efficiently iterate in list of data and search data in another datatable


Search datatable fasterConverting List to a DataTable and/or DataSet Extension MethodsConvert datagridview data to DataTableList<List<string>> vs DataTableIterate over list and valid email addressAdd data to DataTableLeetcode 10: Regular Expression MatchingEfficiently track changes to a List<T>List of classes to datatableHandler for jQuery DataTable search with filters and pagination






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0












$begingroup$


I have a list which has 25000 data and I am iterating in all data and in each iteration, I am searching data in another data table. my whole routine is taking a long time to finish.



private void UpdateCommentFirst(string strCommentPath, string TickerName)

int counter = 0;
bool QcViewAllFileExist = false;
bool QcCommentFileExist = false;
bool AllowUpdate = false;
string savepath = Convert.ToString(ConfigurationManager.AppSettings["OutputPath"]).Trim() + TickerName + "\" + TickerName + "_QC-ViewwAll.xml";
DataSet QCCommentstmp = new DataSet();
DataSet QCViewAlltmp = new DataSet();

if (File.Exists(strCommentPath))

QCCommentstmp.ReadXml(strCommentPath);
QcCommentFileExist = true;


if (File.Exists(savepath))

QCViewAlltmp.ReadXml(savepath);
QcViewAllFileExist = true;


if (QcCommentFileExist && QcViewAllFileExist)

if (QCCommentstmp.Tables.Count > 0)

if (!QCCommentstmp.Tables[0].Columns.Contains("IgnoreData"))

AllowUpdate = true;



if (AllowUpdate)


List<clsCommentPopup> QCCommentlist = QCCommentstmp.Tables[0].AsEnumerable()
.Select(row => new clsCommentPopup

//BrokerFor,Formula,LineItem,Section,PeriodCollection
bolFollowUP = (row.Field<string>("FollowUP")) == null ? false : Convert.ToBoolean((row.Field<string>("FollowUP"))),
bolThisPeriod = (row.Field<string>("ThisPeriod")) == null ? false : Convert.ToBoolean((row.Field<string>("ThisPeriod"))),
Formula = (row.Field<string>("Formula")) == null ? string.Empty : (row.Field<string>("Formula")),
ModelValue = (row.Field<string>("ModelValue")) == null ? string.Empty : (row.Field<string>("ModelValue")),
ExternalComment = (row.Field<string>("ExternalComment")) == null ? string.Empty : (row.Field<string>("ExternalComment")),
InternalComment = (row.Field<string>("InternalComment")) == null ? string.Empty : (row.Field<string>("InternalComment")),
strEndPeriod = (row.Field<string>("EndPeriod")) == null ? string.Empty : (row.Field<string>("EndPeriod")),
strStartPeriod = (row.Field<string>("StartPeriod")) == null ? string.Empty : (row.Field<string>("StartPeriod")),
PeriodType = (row.Field<string>("PeriodType")) == null ? string.Empty : (row.Field<string>("PeriodType")),
SectionFor = (row.Field<string>("Section")) == null ? string.Empty : (row.Field<string>("Section")),
LiFor = (row.Field<string>("LineItem")) == null ? string.Empty : (row.Field<string>("LineItem")),
QcPeriodFor = (row.Field<string>("QcPeriod")) == null ? string.Empty : (row.Field<string>("QcPeriod")),
BrokerFor = (row.Field<string>("BrokerFor")) == null ? string.Empty : (row.Field<string>("BrokerFor")),
PeriodCollection = (row.Field<string>("PeriodCollection")) == null ? string.Empty : (row.Field<string>("PeriodCollection")),
boolIgnoreValue = (row.Field<string>("IgnoreValue")) == null ? false : Convert.ToBoolean((row.Field<string>("IgnoreValue"))),
IgnoreData = (!QCCommentstmp.Tables[0].Columns.Contains("IgnoreData") ? string.Empty : (row.Field<string>("IgnoreData") == null ? string.Empty : row.Field<string>("IgnoreData")))
).ToList();


if (QCCommentlist != null)

foreach (var comment in QCCommentlist)

string section = comment.SectionFor;
string li = comment.LiFor;
string broker = comment.BrokerFor;
string period = comment.PeriodCollection;
string strQCPeriodValue = "";

if (comment.boolIgnoreValue && period.Trim() != "")

var QcViewColumnName = QCViewAlltmp.Tables[0].Columns.Cast<DataColumn>().AsParallel()
.Where(x => x.ColumnName.Contains(period))
.Select(x => new x.ColumnName ).FirstOrDefault();

if (QcViewColumnName != null)

period = QcViewColumnName.ColumnName;

if (period.Trim() != "")

var datarow = QCViewAlltmp.Tables[0].AsEnumerable().AsParallel()
.Where(row => row.Field<string>("GroupKey").Split('~')[0].ToUpper() == section.ToUpper()
&& row.Field<string>("GroupKey").Split('~')[1].ToUpper() == li.ToUpper()
&& row.Field<string>("Section ").ToUpper() == broker.ToUpper());

if (datarow != null && datarow.Count() > 0)

strQCPeriodValue = (datarow.FirstOrDefault()[period] != null ? datarow.FirstOrDefault()[period].ToString() : string.Empty);
if (strQCPeriodValue.Trim() != string.Empty)

comment.IgnoreData = strQCPeriodValue;
counter++;








SerializeQcComment(QCCommentlist);
toolTip1.Hide(this);





loading data from XML file into a dataset.



if ignoredata field is there in QCCommentstmp dataset table QCCommentstmp.Tables[0].Columns.Contains("IgnoreData") then deserialize QCCommentstmp table data to list List<clsCommentPopup> QCCommentlist



iterate in QCCommentlist's data using for loop and finding data in QCViewAlltmp.Tables[0] data table for each iteration



when QCCommentlist has 25000 data then I am iterating in all 25000 data and finding data in another data table. if data found then I am updating data in the list. this process is getting very slow and the code is taking a long time to finish all the iteration and searching data in the data table.



please review my code and tell me how to restructure my code, as a result, there will be the improvement in code execution speed.



If my approach is wrong then guide me with the right approach and also give me the relevant code which I can use in my above code, as a result, my routine will take minimum time to finish if I iterate in more than 25000 data. looking for suggestion & better code to achieve the same task.









share







New contributor




user197025 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$


















    0












    $begingroup$


    I have a list which has 25000 data and I am iterating in all data and in each iteration, I am searching data in another data table. my whole routine is taking a long time to finish.



    private void UpdateCommentFirst(string strCommentPath, string TickerName)

    int counter = 0;
    bool QcViewAllFileExist = false;
    bool QcCommentFileExist = false;
    bool AllowUpdate = false;
    string savepath = Convert.ToString(ConfigurationManager.AppSettings["OutputPath"]).Trim() + TickerName + "\" + TickerName + "_QC-ViewwAll.xml";
    DataSet QCCommentstmp = new DataSet();
    DataSet QCViewAlltmp = new DataSet();

    if (File.Exists(strCommentPath))

    QCCommentstmp.ReadXml(strCommentPath);
    QcCommentFileExist = true;


    if (File.Exists(savepath))

    QCViewAlltmp.ReadXml(savepath);
    QcViewAllFileExist = true;


    if (QcCommentFileExist && QcViewAllFileExist)

    if (QCCommentstmp.Tables.Count > 0)

    if (!QCCommentstmp.Tables[0].Columns.Contains("IgnoreData"))

    AllowUpdate = true;



    if (AllowUpdate)


    List<clsCommentPopup> QCCommentlist = QCCommentstmp.Tables[0].AsEnumerable()
    .Select(row => new clsCommentPopup

    //BrokerFor,Formula,LineItem,Section,PeriodCollection
    bolFollowUP = (row.Field<string>("FollowUP")) == null ? false : Convert.ToBoolean((row.Field<string>("FollowUP"))),
    bolThisPeriod = (row.Field<string>("ThisPeriod")) == null ? false : Convert.ToBoolean((row.Field<string>("ThisPeriod"))),
    Formula = (row.Field<string>("Formula")) == null ? string.Empty : (row.Field<string>("Formula")),
    ModelValue = (row.Field<string>("ModelValue")) == null ? string.Empty : (row.Field<string>("ModelValue")),
    ExternalComment = (row.Field<string>("ExternalComment")) == null ? string.Empty : (row.Field<string>("ExternalComment")),
    InternalComment = (row.Field<string>("InternalComment")) == null ? string.Empty : (row.Field<string>("InternalComment")),
    strEndPeriod = (row.Field<string>("EndPeriod")) == null ? string.Empty : (row.Field<string>("EndPeriod")),
    strStartPeriod = (row.Field<string>("StartPeriod")) == null ? string.Empty : (row.Field<string>("StartPeriod")),
    PeriodType = (row.Field<string>("PeriodType")) == null ? string.Empty : (row.Field<string>("PeriodType")),
    SectionFor = (row.Field<string>("Section")) == null ? string.Empty : (row.Field<string>("Section")),
    LiFor = (row.Field<string>("LineItem")) == null ? string.Empty : (row.Field<string>("LineItem")),
    QcPeriodFor = (row.Field<string>("QcPeriod")) == null ? string.Empty : (row.Field<string>("QcPeriod")),
    BrokerFor = (row.Field<string>("BrokerFor")) == null ? string.Empty : (row.Field<string>("BrokerFor")),
    PeriodCollection = (row.Field<string>("PeriodCollection")) == null ? string.Empty : (row.Field<string>("PeriodCollection")),
    boolIgnoreValue = (row.Field<string>("IgnoreValue")) == null ? false : Convert.ToBoolean((row.Field<string>("IgnoreValue"))),
    IgnoreData = (!QCCommentstmp.Tables[0].Columns.Contains("IgnoreData") ? string.Empty : (row.Field<string>("IgnoreData") == null ? string.Empty : row.Field<string>("IgnoreData")))
    ).ToList();


    if (QCCommentlist != null)

    foreach (var comment in QCCommentlist)

    string section = comment.SectionFor;
    string li = comment.LiFor;
    string broker = comment.BrokerFor;
    string period = comment.PeriodCollection;
    string strQCPeriodValue = "";

    if (comment.boolIgnoreValue && period.Trim() != "")

    var QcViewColumnName = QCViewAlltmp.Tables[0].Columns.Cast<DataColumn>().AsParallel()
    .Where(x => x.ColumnName.Contains(period))
    .Select(x => new x.ColumnName ).FirstOrDefault();

    if (QcViewColumnName != null)

    period = QcViewColumnName.ColumnName;

    if (period.Trim() != "")

    var datarow = QCViewAlltmp.Tables[0].AsEnumerable().AsParallel()
    .Where(row => row.Field<string>("GroupKey").Split('~')[0].ToUpper() == section.ToUpper()
    && row.Field<string>("GroupKey").Split('~')[1].ToUpper() == li.ToUpper()
    && row.Field<string>("Section ").ToUpper() == broker.ToUpper());

    if (datarow != null && datarow.Count() > 0)

    strQCPeriodValue = (datarow.FirstOrDefault()[period] != null ? datarow.FirstOrDefault()[period].ToString() : string.Empty);
    if (strQCPeriodValue.Trim() != string.Empty)

    comment.IgnoreData = strQCPeriodValue;
    counter++;








    SerializeQcComment(QCCommentlist);
    toolTip1.Hide(this);





    loading data from XML file into a dataset.



    if ignoredata field is there in QCCommentstmp dataset table QCCommentstmp.Tables[0].Columns.Contains("IgnoreData") then deserialize QCCommentstmp table data to list List<clsCommentPopup> QCCommentlist



    iterate in QCCommentlist's data using for loop and finding data in QCViewAlltmp.Tables[0] data table for each iteration



    when QCCommentlist has 25000 data then I am iterating in all 25000 data and finding data in another data table. if data found then I am updating data in the list. this process is getting very slow and the code is taking a long time to finish all the iteration and searching data in the data table.



    please review my code and tell me how to restructure my code, as a result, there will be the improvement in code execution speed.



    If my approach is wrong then guide me with the right approach and also give me the relevant code which I can use in my above code, as a result, my routine will take minimum time to finish if I iterate in more than 25000 data. looking for suggestion & better code to achieve the same task.









    share







    New contributor




    user197025 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$














      0












      0








      0





      $begingroup$


      I have a list which has 25000 data and I am iterating in all data and in each iteration, I am searching data in another data table. my whole routine is taking a long time to finish.



      private void UpdateCommentFirst(string strCommentPath, string TickerName)

      int counter = 0;
      bool QcViewAllFileExist = false;
      bool QcCommentFileExist = false;
      bool AllowUpdate = false;
      string savepath = Convert.ToString(ConfigurationManager.AppSettings["OutputPath"]).Trim() + TickerName + "\" + TickerName + "_QC-ViewwAll.xml";
      DataSet QCCommentstmp = new DataSet();
      DataSet QCViewAlltmp = new DataSet();

      if (File.Exists(strCommentPath))

      QCCommentstmp.ReadXml(strCommentPath);
      QcCommentFileExist = true;


      if (File.Exists(savepath))

      QCViewAlltmp.ReadXml(savepath);
      QcViewAllFileExist = true;


      if (QcCommentFileExist && QcViewAllFileExist)

      if (QCCommentstmp.Tables.Count > 0)

      if (!QCCommentstmp.Tables[0].Columns.Contains("IgnoreData"))

      AllowUpdate = true;



      if (AllowUpdate)


      List<clsCommentPopup> QCCommentlist = QCCommentstmp.Tables[0].AsEnumerable()
      .Select(row => new clsCommentPopup

      //BrokerFor,Formula,LineItem,Section,PeriodCollection
      bolFollowUP = (row.Field<string>("FollowUP")) == null ? false : Convert.ToBoolean((row.Field<string>("FollowUP"))),
      bolThisPeriod = (row.Field<string>("ThisPeriod")) == null ? false : Convert.ToBoolean((row.Field<string>("ThisPeriod"))),
      Formula = (row.Field<string>("Formula")) == null ? string.Empty : (row.Field<string>("Formula")),
      ModelValue = (row.Field<string>("ModelValue")) == null ? string.Empty : (row.Field<string>("ModelValue")),
      ExternalComment = (row.Field<string>("ExternalComment")) == null ? string.Empty : (row.Field<string>("ExternalComment")),
      InternalComment = (row.Field<string>("InternalComment")) == null ? string.Empty : (row.Field<string>("InternalComment")),
      strEndPeriod = (row.Field<string>("EndPeriod")) == null ? string.Empty : (row.Field<string>("EndPeriod")),
      strStartPeriod = (row.Field<string>("StartPeriod")) == null ? string.Empty : (row.Field<string>("StartPeriod")),
      PeriodType = (row.Field<string>("PeriodType")) == null ? string.Empty : (row.Field<string>("PeriodType")),
      SectionFor = (row.Field<string>("Section")) == null ? string.Empty : (row.Field<string>("Section")),
      LiFor = (row.Field<string>("LineItem")) == null ? string.Empty : (row.Field<string>("LineItem")),
      QcPeriodFor = (row.Field<string>("QcPeriod")) == null ? string.Empty : (row.Field<string>("QcPeriod")),
      BrokerFor = (row.Field<string>("BrokerFor")) == null ? string.Empty : (row.Field<string>("BrokerFor")),
      PeriodCollection = (row.Field<string>("PeriodCollection")) == null ? string.Empty : (row.Field<string>("PeriodCollection")),
      boolIgnoreValue = (row.Field<string>("IgnoreValue")) == null ? false : Convert.ToBoolean((row.Field<string>("IgnoreValue"))),
      IgnoreData = (!QCCommentstmp.Tables[0].Columns.Contains("IgnoreData") ? string.Empty : (row.Field<string>("IgnoreData") == null ? string.Empty : row.Field<string>("IgnoreData")))
      ).ToList();


      if (QCCommentlist != null)

      foreach (var comment in QCCommentlist)

      string section = comment.SectionFor;
      string li = comment.LiFor;
      string broker = comment.BrokerFor;
      string period = comment.PeriodCollection;
      string strQCPeriodValue = "";

      if (comment.boolIgnoreValue && period.Trim() != "")

      var QcViewColumnName = QCViewAlltmp.Tables[0].Columns.Cast<DataColumn>().AsParallel()
      .Where(x => x.ColumnName.Contains(period))
      .Select(x => new x.ColumnName ).FirstOrDefault();

      if (QcViewColumnName != null)

      period = QcViewColumnName.ColumnName;

      if (period.Trim() != "")

      var datarow = QCViewAlltmp.Tables[0].AsEnumerable().AsParallel()
      .Where(row => row.Field<string>("GroupKey").Split('~')[0].ToUpper() == section.ToUpper()
      && row.Field<string>("GroupKey").Split('~')[1].ToUpper() == li.ToUpper()
      && row.Field<string>("Section ").ToUpper() == broker.ToUpper());

      if (datarow != null && datarow.Count() > 0)

      strQCPeriodValue = (datarow.FirstOrDefault()[period] != null ? datarow.FirstOrDefault()[period].ToString() : string.Empty);
      if (strQCPeriodValue.Trim() != string.Empty)

      comment.IgnoreData = strQCPeriodValue;
      counter++;








      SerializeQcComment(QCCommentlist);
      toolTip1.Hide(this);





      loading data from XML file into a dataset.



      if ignoredata field is there in QCCommentstmp dataset table QCCommentstmp.Tables[0].Columns.Contains("IgnoreData") then deserialize QCCommentstmp table data to list List<clsCommentPopup> QCCommentlist



      iterate in QCCommentlist's data using for loop and finding data in QCViewAlltmp.Tables[0] data table for each iteration



      when QCCommentlist has 25000 data then I am iterating in all 25000 data and finding data in another data table. if data found then I am updating data in the list. this process is getting very slow and the code is taking a long time to finish all the iteration and searching data in the data table.



      please review my code and tell me how to restructure my code, as a result, there will be the improvement in code execution speed.



      If my approach is wrong then guide me with the right approach and also give me the relevant code which I can use in my above code, as a result, my routine will take minimum time to finish if I iterate in more than 25000 data. looking for suggestion & better code to achieve the same task.









      share







      New contributor




      user197025 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      I have a list which has 25000 data and I am iterating in all data and in each iteration, I am searching data in another data table. my whole routine is taking a long time to finish.



      private void UpdateCommentFirst(string strCommentPath, string TickerName)

      int counter = 0;
      bool QcViewAllFileExist = false;
      bool QcCommentFileExist = false;
      bool AllowUpdate = false;
      string savepath = Convert.ToString(ConfigurationManager.AppSettings["OutputPath"]).Trim() + TickerName + "\" + TickerName + "_QC-ViewwAll.xml";
      DataSet QCCommentstmp = new DataSet();
      DataSet QCViewAlltmp = new DataSet();

      if (File.Exists(strCommentPath))

      QCCommentstmp.ReadXml(strCommentPath);
      QcCommentFileExist = true;


      if (File.Exists(savepath))

      QCViewAlltmp.ReadXml(savepath);
      QcViewAllFileExist = true;


      if (QcCommentFileExist && QcViewAllFileExist)

      if (QCCommentstmp.Tables.Count > 0)

      if (!QCCommentstmp.Tables[0].Columns.Contains("IgnoreData"))

      AllowUpdate = true;



      if (AllowUpdate)


      List<clsCommentPopup> QCCommentlist = QCCommentstmp.Tables[0].AsEnumerable()
      .Select(row => new clsCommentPopup

      //BrokerFor,Formula,LineItem,Section,PeriodCollection
      bolFollowUP = (row.Field<string>("FollowUP")) == null ? false : Convert.ToBoolean((row.Field<string>("FollowUP"))),
      bolThisPeriod = (row.Field<string>("ThisPeriod")) == null ? false : Convert.ToBoolean((row.Field<string>("ThisPeriod"))),
      Formula = (row.Field<string>("Formula")) == null ? string.Empty : (row.Field<string>("Formula")),
      ModelValue = (row.Field<string>("ModelValue")) == null ? string.Empty : (row.Field<string>("ModelValue")),
      ExternalComment = (row.Field<string>("ExternalComment")) == null ? string.Empty : (row.Field<string>("ExternalComment")),
      InternalComment = (row.Field<string>("InternalComment")) == null ? string.Empty : (row.Field<string>("InternalComment")),
      strEndPeriod = (row.Field<string>("EndPeriod")) == null ? string.Empty : (row.Field<string>("EndPeriod")),
      strStartPeriod = (row.Field<string>("StartPeriod")) == null ? string.Empty : (row.Field<string>("StartPeriod")),
      PeriodType = (row.Field<string>("PeriodType")) == null ? string.Empty : (row.Field<string>("PeriodType")),
      SectionFor = (row.Field<string>("Section")) == null ? string.Empty : (row.Field<string>("Section")),
      LiFor = (row.Field<string>("LineItem")) == null ? string.Empty : (row.Field<string>("LineItem")),
      QcPeriodFor = (row.Field<string>("QcPeriod")) == null ? string.Empty : (row.Field<string>("QcPeriod")),
      BrokerFor = (row.Field<string>("BrokerFor")) == null ? string.Empty : (row.Field<string>("BrokerFor")),
      PeriodCollection = (row.Field<string>("PeriodCollection")) == null ? string.Empty : (row.Field<string>("PeriodCollection")),
      boolIgnoreValue = (row.Field<string>("IgnoreValue")) == null ? false : Convert.ToBoolean((row.Field<string>("IgnoreValue"))),
      IgnoreData = (!QCCommentstmp.Tables[0].Columns.Contains("IgnoreData") ? string.Empty : (row.Field<string>("IgnoreData") == null ? string.Empty : row.Field<string>("IgnoreData")))
      ).ToList();


      if (QCCommentlist != null)

      foreach (var comment in QCCommentlist)

      string section = comment.SectionFor;
      string li = comment.LiFor;
      string broker = comment.BrokerFor;
      string period = comment.PeriodCollection;
      string strQCPeriodValue = "";

      if (comment.boolIgnoreValue && period.Trim() != "")

      var QcViewColumnName = QCViewAlltmp.Tables[0].Columns.Cast<DataColumn>().AsParallel()
      .Where(x => x.ColumnName.Contains(period))
      .Select(x => new x.ColumnName ).FirstOrDefault();

      if (QcViewColumnName != null)

      period = QcViewColumnName.ColumnName;

      if (period.Trim() != "")

      var datarow = QCViewAlltmp.Tables[0].AsEnumerable().AsParallel()
      .Where(row => row.Field<string>("GroupKey").Split('~')[0].ToUpper() == section.ToUpper()
      && row.Field<string>("GroupKey").Split('~')[1].ToUpper() == li.ToUpper()
      && row.Field<string>("Section ").ToUpper() == broker.ToUpper());

      if (datarow != null && datarow.Count() > 0)

      strQCPeriodValue = (datarow.FirstOrDefault()[period] != null ? datarow.FirstOrDefault()[period].ToString() : string.Empty);
      if (strQCPeriodValue.Trim() != string.Empty)

      comment.IgnoreData = strQCPeriodValue;
      counter++;








      SerializeQcComment(QCCommentlist);
      toolTip1.Hide(this);





      loading data from XML file into a dataset.



      if ignoredata field is there in QCCommentstmp dataset table QCCommentstmp.Tables[0].Columns.Contains("IgnoreData") then deserialize QCCommentstmp table data to list List<clsCommentPopup> QCCommentlist



      iterate in QCCommentlist's data using for loop and finding data in QCViewAlltmp.Tables[0] data table for each iteration



      when QCCommentlist has 25000 data then I am iterating in all 25000 data and finding data in another data table. if data found then I am updating data in the list. this process is getting very slow and the code is taking a long time to finish all the iteration and searching data in the data table.



      please review my code and tell me how to restructure my code, as a result, there will be the improvement in code execution speed.



      If my approach is wrong then guide me with the right approach and also give me the relevant code which I can use in my above code, as a result, my routine will take minimum time to finish if I iterate in more than 25000 data. looking for suggestion & better code to achieve the same task.







      c#





      share







      New contributor




      user197025 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      user197025 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      user197025 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 4 mins ago









      user197025user197025

      1




      1




      New contributor




      user197025 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      user197025 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      user197025 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          0






          active

          oldest

          votes












          Your Answer





          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          user197025 is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216990%2fhow-to-efficiently-iterate-in-list-of-data-and-search-data-in-another-datatable%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          user197025 is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          user197025 is a new contributor. Be nice, and check out our Code of Conduct.












          user197025 is a new contributor. Be nice, and check out our Code of Conduct.











          user197025 is a new contributor. Be nice, and check out our Code of Conduct.














          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216990%2fhow-to-efficiently-iterate-in-list-of-data-and-search-data-in-another-datatable%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          बाताम इन्हें भी देखें सन्दर्भ दिक्चालन सूची1°05′00″N 104°02′0″E / 1.08333°N 104.03333°E / 1.08333; 104.033331°05′00″N 104°02′0″E / 1.08333°N 104.03333°E / 1.08333; 104.03333

          Why is the 'in' operator throwing an error with a string literal instead of logging false?Why can't I use switch statement on a String?Python join: why is it string.join(list) instead of list.join(string)?Multiline String Literal in C#Why does comparing strings using either '==' or 'is' sometimes produce a different result?How to initialize an array's length in javascript?How can I print literal curly-brace characters in python string and also use .format on it?Why does ++[[]][+[]]+[+[]] return the string “10”?Why is char[] preferred over String for passwords?Why does this code using random strings print “hello world”?jQuery.inArray(), how to use it right?

          How can we generalize the fact of finite dimensional vector space to an infinte dimensional case?$k[x]$-module and cyclic module over a finite dimensional vector spaceSubspace of a finite dimensional space is finite dimensionalIf V is an infinite-dimensional vector space, and S is an infinite-dimensional subspace of V, must the dimension of V/S be finite? ExplainWhy is an infinite dimensional space so different than a finite dimensional one?base for finite dimensional vector space is not infinite dimensional vector space?Any finite-dimensional vector space is the dual space of anotherHaving Trouble Understanding Meaning Of A Finite-Dimensional Vector SpaceProve that “Every subspaces of a finite-dimensional vector space is finite-dimensional”Ring as a finite dimensional Vector space over a field KQuestion regarding basis and dimension