Array Problem With Datatable?

VonEhle

Active member
Joined
Feb 20, 2006
Messages
26
Programming Experience
Beginner
I have a datatable that keeps a running cost total of all items in the table. I'm trying to make it so I can also keep track of each individual line for future purposes. When I run it as shown below, I get an error that says "Object reference not set to an instance of an object." The error points to the line of code with the array.

VB.NET:
For intCounter = 0 To objDT.Rows.Count - 1
objDR = objDT.Rows(intCounter)
decLineCost = (objDR("Cost") * objDR("Quantity"))
decRunningTotal += decLineCost
[COLOR=red]strLineCost(intCounter) = decLineCost.ToString[/COLOR]
Next
 
I would suggest adding another column to your DataTable and setting its Expression property to "Cost * Quantity". It will than automatically calculate the value for you. If you want the total amount for the table you would then use the Compute method, e.g. myDataTable.Compute("SUM(Amount)"), which will return a single value that sums your entire calculated column.
 
Back
Top