Hello. I am having trouble combining records from a datatable. I combined two tables into one virtual table called dt. There are four columns called itemID, description,Inventory.quantity and Orders.quantity. What I want to do is search through the datatable and if there are duplicate itemID's I want to keep a running total of the Orders.quantity. When finished I want to display in a list box, each itemID, its description with its total Orders.quantity.
Here is what I have but cannot get working right.
For i = 0 To dt.Rows.Count - 1
If i = 0 Then
lstResult.Items.Add(""
ElseIf dt.Rows(i)(3) = dt.Rows(i - 1)(3) Then
Q = dt.Rows(0)(3)
Q = Q + dt.Rows(i)(3)
End If
lstResult.Items.Add(String.Format(fmtStr,dt.Rows(i)(0),dt.Rows(i)(1),dt.Rows(i)(2),dt.Rows(i)(3),Q))
Next
Any help would be greatly appreciated.
Here is what I have but cannot get working right.
For i = 0 To dt.Rows.Count - 1
If i = 0 Then
lstResult.Items.Add(""
ElseIf dt.Rows(i)(3) = dt.Rows(i - 1)(3) Then
Q = dt.Rows(0)(3)
Q = Q + dt.Rows(i)(3)
End If
lstResult.Items.Add(String.Format(fmtStr,dt.Rows(i)(0),dt.Rows(i)(1),dt.Rows(i)(2),dt.Rows(i)(3),Q))
Next
Any help would be greatly appreciated.