Hi friends i am getting outofmemoryexception, Here is my code which is in italic i have to optimized these nested loops to avoid the exception.

I am telling the background here ,I have a condition in which i have Dataset A,Dataset B and Dataset C.Dataset A is parent & the remaing are childs,I have to merge Dataset B & dataset C in Dataset A wrt loanmasterid

case Constants.Reports.UHrptLoanSummarybatch:
                    rptData = dbHelper.Get_Loan_Summary_Batch(objReportHelper.CustomerId, objReportHelper.AuditId);//  parent  table
                    rptData2 = dbHelper.Get_Other_Comments_Batch(objReportHelper.CustomerId, objReportHelper.AuditId);
                    rptData4 = dbHelper.Get_Audit_Details_Batch(objReportHelper.CustomerId, objReportHelper.AuditId);

                    rptData.DataSetName = "spReport_LoanSummaryBatch_edit";

                    foreach (DataColumn col in rptData2.Tables[0].Columns)
                    {
                        if(!rptData.Tables[0].Columns.Contains(col.ColumnName))
                            rptData.Tables[0].Columns.Add(col.ColumnName);
                    }

                    foreach (DataColumn col in rptData4.Tables[0].Columns)
                    {
                        if(!rptData.Tables[0].Columns.Contains(col.ColumnName))
                            rptData.Tables[0].Columns.Add(col.ColumnName);
                    }

                    DataRow [] dRows;
                    DataRow parentRow;
                    DataRow newRow;

                    //for (int i = 0; i < rptData.Tables[0].Rows.Count; i++)
                    //{
                    //    parentRow = rptData.Tables[0].Rows[i];

                    //    dRows = rptData2.Tables[0].Select("loanmasterid=" + parentRow["loanmasterid"].ToString());

                    //    foreach (DataRow childRow in dRows)
                    //    {
                    //        newRow = rptData.Tables[0].NewRow();

                    //        foreach (DataColumn childCOl in rptData2.Tables[0].Columns)
                    //        {
                    //            newRow[childCOl.ColumnName] = childRow[childCOl.ColumnName];
                    //        }

                    //        rptData.Tables[0].Rows.Add(newRow);

                    //    }
                    //}

                    for (int i = 0; i < rptData.Tables[0].Rows.Count; i++)
                    {
                        parentRow = rptData.Tables[0].Rows[i];

                        dRows = rptData4.Tables[0].Select("loanmasterid=" + parentRow["loanmasterid"].ToString());

                        foreach (DataRow childRow in dRows)
                        {
                           newRow = rptData.Tables[0].NewRow();

                            foreach (DataColumn childCOl in rptData4.Tables[0].Columns)
                            {
                                newRow[childCOl.ColumnName] = childRow[childCOl.ColumnName];
                            }

                            rptData.Tables[0].Rows.Add(newRow);

                        }
                    }






                    objReportDataSource = new ReportDataSource("spReport_LoanSummaryBatch_edit", rptData4.Tables[0]);



                    objReportDataSource4 = new ReportDataSource("spReport_LoanSummaryBatch_edit", rptData4.Tables[0]);





                    ReportViewer1.LocalReport.ReportPath = "Reports/UHrptLoanSummarybatch.rdlc";

                    break;
This article has been dead for over six months. Start a new discussion instead.