By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,616 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

outofmemoryexception due to nested for loop

P: 27
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.


Expand|Select|Wrap|Line Numbers
  1. case Constants.Reports.UHrptLoanSummarybatch:
  2.                     rptData = dbHelper.Get_Loan_Summary_Batch(objReportHelper.CustomerId, objReportHelper.AuditId);//  parent  table
  3.                     rptData2 = dbHelper.Get_Other_Comments_Batch(objReportHelper.CustomerId, objReportHelper.AuditId);
  4.                     rptData4 = dbHelper.Get_Audit_Details_Batch(objReportHelper.CustomerId, objReportHelper.AuditId);
  5.  
  6.                     rptData.DataSetName = "spReport_LoanSummaryBatch_edit";
  7.  
  8.                     foreach (DataColumn col in rptData2.Tables[0].Columns)
  9.                     {
  10.                         if(!rptData.Tables[0].Columns.Contains(col.ColumnName))
  11.                             rptData.Tables[0].Columns.Add(col.ColumnName);
  12.                     }
  13.  
  14.                     foreach (DataColumn col in rptData4.Tables[0].Columns)
  15.                     {
  16.                         if(!rptData.Tables[0].Columns.Contains(col.ColumnName))
  17.                             rptData.Tables[0].Columns.Add(col.ColumnName);
  18.                     }
  19.  
  20.                     DataRow [] dRows;
  21.                     DataRow parentRow;
  22.                     DataRow newRow;
  23.  
  24.                     //for (int i = 0; i < rptData.Tables[0].Rows.Count; i++)
  25.                     //{
  26.                     //    parentRow = rptData.Tables[0].Rows[i];
  27.  
  28.                     //    dRows = rptData2.Tables[0].Select("loanmasterid=" + parentRow["loanmasterid"].ToString());
  29.  
  30.                     //    foreach (DataRow childRow in dRows)
  31.                     //    {
  32.                     //        newRow = rptData.Tables[0].NewRow();
  33.  
  34.                     //        foreach (DataColumn childCOl in rptData2.Tables[0].Columns)
  35.                     //        {
  36.                     //            newRow[childCOl.ColumnName] = childRow[childCOl.ColumnName];
  37.                     //        }
  38.  
  39.                     //        rptData.Tables[0].Rows.Add(newRow);
  40.  
  41.                     //    }
  42.                     //}
  43.  
  44.                     for (int i = 0; i < rptData.Tables[0].Rows.Count; i++)
  45.                     {
  46.                         parentRow = rptData.Tables[0].Rows[i];
  47.  
  48.                         dRows = rptData4.Tables[0].Select("loanmasterid=" + parentRow["loanmasterid"].ToString());
  49.  
  50.                         foreach (DataRow childRow in dRows)
  51.                         {
  52.                            newRow = rptData.Tables[0].NewRow();
  53.  
  54.                             foreach (DataColumn childCOl in rptData4.Tables[0].Columns)
  55.                             {
  56.                                 newRow[childCOl.ColumnName] = childRow[childCOl.ColumnName];
  57.                             }
  58.  
  59.                             rptData.Tables[0].Rows.Add(newRow);
  60.  
  61.                         }
  62.                     }
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.                     objReportDataSource = new ReportDataSource("spReport_LoanSummaryBatch_edit", rptData4.Tables[0]);
  70.  
  71.  
  72.  
  73.                     objReportDataSource4 = new ReportDataSource("spReport_LoanSummaryBatch_edit", rptData4.Tables[0]);
  74.  
  75.  
  76.  
  77.  
  78.  
  79.                     ReportViewer1.LocalReport.ReportPath = "Reports/UHrptLoanSummarybatch.rdlc";
  80.  
  81.                     break;
  82.  
  83.  
  84.  
  85.  
Nov 4 '12 #1
Share this Question
Share on Google+
1 Reply


Rabbit
Expert Mod 10K+
P: 12,347
I don't see any italicized code but I assume you're talking about the rows that have been commented out. It would help to know the purpose of the code.
Nov 4 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.