I have a master datatable with invoice records sorted by invoice# . And I have another datable with details (line item information) for all those invoice records sorted by invoice no & line item no.
How can I effectively create an array of invoice objects from these two tables. For me it looks like creating nested for loops ..The outer for loop traverses the orders table and the inner for loop navigates through the line items table
And I will keep a temp identifier which holds the current invoice# and once it finds a different invoice# in the nested for loop , it will exit the inner loop .
Below is the pseudo code which I am trying to do
long currentInvoiceNumber=-1;
int CurrentJCounter=0;
for(int i=0;i<MasterTable.Rows.Count;i++)
{
currentInvoiceNumber=MasterTable.Rows[i]["invoiceno"];
Order oOrder = new Order();
for(int j=CurrentJCounter;j<ItemDetailsTable.Row.Count;j++)
{
if(currentInvoiceNumber!=ItemDetailsTable.Rows[j]["invoiceno"])
{
currentJCounter = j;
break;
}
else
{
oOrder.AddItem(ItemDetailsTable.Rows[j]);
}
}
lstOrders.Add(oOrder);
}
I have to improve the performance of the appln and i think there would be definitely a better approach than this. Please suggest
Thanks, Sveerap