473,396 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

outofmemoryexception due to nested for loop

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
1 1630
Rabbit
12,516 Expert Mod 8TB
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

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

Similar topics

25
by: chad | last post by:
I am writing a program to do some reliability calculations that require several nested for-loops. However, I believe that as the models become more complex, the number of required for-loops will...
0
by: John Wilson | last post by:
Hello, I have the following code which populates as table data from a SQL Server 2000 stored proc (RSByDemoID2). Below that is the view and stored procedure which takes @DemoID as input to match...
1
by: mhk | last post by:
Hi, i have a nested loop in Javascript and i have a break statement in inner loop. As break statement takes control come out of inner loop. I want to come out of both loops if break statement...
2
by: smauldin | last post by:
Why does the execution plan have a nested loop join for a simple select with an UDF in the where clause? Here is the query: select * from test_plan where vCol = my_udf('test') Here is the...
5
by: Blankdraw | last post by:
I can't get this nested loop to break the outer loop at the 5th data value so control can proceed to the next array col and continue pigeon-holing the next 5 in its own column. Why can I not get...
18
by: Derek Basch | last post by:
What is the best way to count nested loop iterations? I can only figure to use an index but that seems kludgy. index = 0 for animal in zoo: for color in animal: index += 1 Thanks, Derek...
1
by: Goldie | last post by:
Can anyone offer advice on how to do a nested loop with vb I need the loop nested in the main loop to be passed a variable from the parent loop for SQL purposes. eg: parent selects all...
12
by: upernikaw | last post by:
Hello, I am attempting to create a nested loop (in Access 2003/VB) that will print a report for a set of user defined months inputed on a form and that will print out for every Client. So the first...
3
by: volunteerguy | last post by:
one more quick question, this isn't complicated but somehow i'm causing infinnite loop when i attempt it. given the following code... starting after the first printf i need everything else to...
8
by: TobbeK | last post by:
Need some help with a nested loop. This one (my example code below) prints out a correct 3 column HTML table with the recordset with proper opening and closing HTML tags AS LONG as the GRUOP BY...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.