First thing you need to check is that all the data tables passed in your method should not be initialized rather than
Nothing.
For example, the start of method will be something like this:
Public Sub Plot_TotalPerItem(ByRef NewTable As DataTable, ByVal Items As DataTable, ByVal Total_PerItem As DataTable)
If(NewTable Is Nothing OR Items Is Nothing OR Total_PerItem Is Nothing)
return
End if
Try
For Each total As DataRow In Total_PerItem.Rows
..
..
..
In this case following line will not break:
For Each total As DataRow In Total_PerItem.Rows
Second thing is this part:
If total.Item("ItemCode") = item.Item("ItemCode") And total.Item("ItemClass") = item.Item("ItemClass") Then
If you want to take decision on the basis of two conditions then prefer
AndAlso rather than
And.
AndAlso helps to evaluate one condition at a time Read it from
here.
Then
check for NULL values
Finally, check any missing column name:
item.Item("ItemCode")
I hope it can help you to figure out problem.