Response to: object reference not set to an instance of an object VB.NET
Revision 3
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: (In this case following line will not break:
For Each total As DataRow In Total_PerItem.Rows)
Public Sub Plot_TotalPerItem(ByRef NewTable As DataTable, ByVal Items As DataTable, ByVal Total_PerItem As DataTable)
If(NewTable Is Nothing OR NewTable Is Nothing OR NewTable Is Nothing)
return
End if
Try
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.
Posted 11-Oct-12 0:20am
by
Shahan Ayyub.