In my vb.net project, I have this form, which is used for adding additional charges onto orders (delivery costs, for example).
In this example, the freight number is the same, because the freight is for the full order, rather than having freight for each line. However, there is an option to add a different freight value to each individual order line, so the numbers would be different (eg, 7 and 8), and so would the value for each line.
When the Add button is pressed, either the line or the order (depending on how freight is being added), is added to the grid labelled 'Freight'. But, the data is only stored in a
SQL SELECT DISTINCT
If freightTable.Rows.Count = 0 Then
txtTotal.Text = "0.00"
Dim tot As Double = 0
Dim i As Integer = 0
For i = 0 To freightTable.Rows.Count - 1
tot = tot + Convert.ToDouble(ugFreight.Rows(i).Cells("Freight_Val").Value)
txtTotal.Text = tot
Keep a note of which freight values you have seem in a list.
Dim freightDone As New List(Of Integer) For i = 0 To freightTable.Rows.Count - 1 Dim currentFreigth as Integer = Convert.ToInteger( ugFreight.Rows(i).Cells("Freight_#").Value ) If Not freightDone.Contains(currentFreigth) Then tot = tot + Convert.ToDouble(ugFreight.Rows(i).Cells("Freight_Val").Value) freightDone.Add(currentFreigth) End If Next i
(You may have to change the definition of currentFreigth to fit your datatable column name, or my slightly rusty VB.)