Click here to Skip to main content
15,887,267 members
Home / Discussions / C#
   

C#

 
AnswerRe: Application Server and Connection Method Pin
Mycroft Holmes9-Apr-19 12:29
professionalMycroft Holmes9-Apr-19 12:29 
QuestionIPV6 Compatibility Pin
chain singh aanjana7-Apr-19 20:37
chain singh aanjana7-Apr-19 20:37 
AnswerRe: IPV6 Compatibility Pin
Gerry Schmitz8-Apr-19 5:47
mveGerry Schmitz8-Apr-19 5:47 
QuestionHow to add second column to a listBox component? Pin
Member 140558797-Apr-19 9:13
Member 140558797-Apr-19 9:13 
AnswerRe: How to add second column to a listBox component? Pin
Mycroft Holmes7-Apr-19 12:27
professionalMycroft Holmes7-Apr-19 12:27 
AnswerRe: How to add second column to a listBox component? Pin
BillWoodruff7-Apr-19 16:27
professionalBillWoodruff7-Apr-19 16:27 
AnswerRe: How to add second column to a listBox component? Pin
Gerry Schmitz8-Apr-19 5:20
mveGerry Schmitz8-Apr-19 5:20 
QuestionIterating in a list of data and search that data in another datatable for update first list Pin
Mou_kol7-Apr-19 8:15
Mou_kol7-Apr-19 8:15 
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.
C#
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 the ignoredata field is there in QCCommentstmp dataset table
C#
QCCommentstmp.Tables[0].Columns.Contains("IgnoreData")
then deserialize QCCommentstmp table data to list List<clscommentpopup> QCCommentlist.

Iterate in QCCommentlist's data using a 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 is 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. I'm looking for suggestions and better code to achieve the same task. thanks
AnswerRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Luc Pattyn7-Apr-19 15:51
sitebuilderLuc Pattyn7-Apr-19 15:51 
GeneralRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Mou_kol8-Apr-19 9:13
Mou_kol8-Apr-19 9:13 
GeneralRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Luc Pattyn8-Apr-19 9:15
sitebuilderLuc Pattyn8-Apr-19 9:15 
AnswerRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Eddy Vluggen8-Apr-19 0:23
professionalEddy Vluggen8-Apr-19 0:23 
GeneralRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Mou_kol8-Apr-19 9:14
Mou_kol8-Apr-19 9:14 
GeneralRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Eddy Vluggen9-Apr-19 2:02
professionalEddy Vluggen9-Apr-19 2:02 
AnswerRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Gerry Schmitz8-Apr-19 5:39
mveGerry Schmitz8-Apr-19 5:39 
AnswerRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Luc Pattyn8-Apr-19 11:50
sitebuilderLuc Pattyn8-Apr-19 11:50 
GeneralRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Mou_kol9-Apr-19 9:14
Mou_kol9-Apr-19 9:14 
GeneralRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Mou_kol11-Apr-19 8:58
Mou_kol11-Apr-19 8:58 
GeneralRe: Iterating in a list of data and search that data in another datatable for update first list Pin
Luc Pattyn11-Apr-19 9:17
sitebuilderLuc Pattyn11-Apr-19 9:17 
QuestionHow to do three join between three list Pin
Mou_kol7-Apr-19 8:12
Mou_kol7-Apr-19 8:12 
AnswerRe: How to do three join between three list Pin
User 41802549-Apr-19 3:22
User 41802549-Apr-19 3:22 
QuestionRepeated join causing poor performance in for loop Pin
Mou_kol7-Apr-19 8:10
Mou_kol7-Apr-19 8:10 
AnswerRe: Repeated join causing poor performance in for loop Pin
jschell7-Apr-19 8:57
jschell7-Apr-19 8:57 
GeneralRe: Repeated join causing poor performance in for loop Pin
Mou_kol8-Apr-19 9:07
Mou_kol8-Apr-19 9:07 
AnswerRe: Repeated join causing poor performance in for loop Pin
Luc Pattyn7-Apr-19 15:44
sitebuilderLuc Pattyn7-Apr-19 15:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.