Project Entry -> how to iterate through JobOper table/dataset from JobEntry Adapter?

I’m working on a customization for Project Entry, where I have a custom numeric control, and I would like to populate that with a calculation: the sum of a particular UD field on JobOper for all the Jobs linked to the project.

My strategy is to loop through the jobs listed in the “ProjectJob” dataview:

For each job, use the JobEntry adapter, and do GetByID(JobNum), then loop through the JobOper dataset and add up the values on each row. So for this example, here are all the related operations for this project. This is directly querying the JobOper table, and I have displayed the sum that I want populating that custom control.

As you can see, 21 rows with a total of 13,487.00. But when I load the project, the total is showing something much higher than it should:

image

I’m just using the message boxes for now to debug it, and it appears that it is multi-counting the JobOper rows, like this. When it looks at the 402156-1-1, it looks at two rows, but when it goes to the 402156-3-1, it looks at the two from that job PLUS the two from the first job (4 total), and when it gets to the 402156-4-1, it looks at the two from the -1-1 job, the -3-1 job, AND the -4-1 job, for 6 total, and so on…

Here’s my code, which I’m attempting as a basic nested loop. Can anyone tell me where I’m going wrong? Thanks in advance.

public void TotalBudLabHours()
	{
		decimal totBudHrsValue = 0;
		
		string jobNumstr;
		
		JobEntryAdapter jeAdap  = new JobEntryAdapter(oTrans);
		jeAdap.BOConnect();

		foreach (DataRow row in edvProjectJob.dataView.Table.Rows)
		{
			
			jobNumstr = Convert.ToString(row["JobNum"]);

			jeAdap.GetByID(jobNumstr);
			
			decimal totHrsSubtotal = 0;
			
			foreach (DataRow jobOpRow in jeAdap.JobEntryData.JobOper.Rows)
			{			
				totHrsSubtotal = totHrsSubtotal + Convert.ToDecimal(jobOpRow["Budget_LaborHrs_c"]);			
			}		
						
			totBudHrsValue = totBudHrsValue + totHrsSubtotal;
			
		}
	
		
		numProjectTotalBudHrs.Value = totBudHrsValue;
		jeAdap.Dispose();
		
	}

OK, just after I posted this, I got the idea to put the call for the JobEntry Adapter inside the outer loop, instead of right before it, and dispose of it at the end of it, and wouldn’cha know:

image

You could have also just cleared the dataset in between calls.

How would I have done that, is it like the Dispose() method?

jeAdap.JobEntryData.Clear()