I am new to Visual Basic Express and I am working on a simple application but I can't figure this out. It's probably easy and right in front of my face but I just can't get it. I have two tables - one with a list of ORDERS (product type, date, employee completing sale, etc) and one with the DETAIL concerning those orders (name of each product, price, etc). They are linked by a one to many relationship using an order ID number. My form has a detail grid that shows the DETAIL based on the selected order ID. I would like to have a textbox on the form that calculates the sum of the prices in the data grid for that order ID. I was able to do something like this in Access by inserting an expression into the textbox but I don't see anything like that available in VB Express. What can I do to accomplish this



Re: Visual Basic Express Edition How do I show the sum of a table column in a textbox?


Hi use this code that I had used before:
Public Sub UpdateTotalAmount()
Dim TotalAmount As Decimal = 0
Dim TempAmount As Decimal = 0
Dim Tax As Decimal
Tax = Val(POS.txtTax.Text) / 100
For Each row As DataGridViewRow In POS.DataGridBasketList.Rows
TempAmount = row.Cells(4).Value 'your price column
TotalAmount = (TotalAmount + TempAmount)
TotalAmount = TotalAmount * (1 + Tax)

POS.txtTotalAmount.Text = TotalAmount '.ToString("P #,##0.00")

Catch ex As Exception
End Try
End Sub

Re: Visual Basic Express Edition How do I show the sum of a table column in a textbox?

Andrej Tozon


if you're working with DataTables, you can perform aggregate function over its rows. For example, table.Compute("sum(price)", "") would calculate the sum on all rows over price column in your DataTable. The second parameter of Compute methods takes the row filter condition, allowing you to include just some specific rows in your calculations.