peabrain25

Hello,

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

Thanks!

Mark


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

ChrisMoje

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
Try
For Each row As DataGridViewRow In POS.DataGridBasketList.Rows
TempAmount = row.Cells(4).Value 'your price column
TotalAmount = (TotalAmount + TempAmount)
Next
TotalAmount = TotalAmount * (1 + Tax)

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

Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub





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

Andrej Tozon

Hi,

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.

Andrej