,我要如何获得totalPrice的总和我的datagridview从MySQL我怎么总从DataGridView vb.net总和
ProductName Qty. Price totalPrice
2 Pcs. Chickenjoy 5 59 295
2 Pcs. Chickenjoy 1 69 69
2 Pcs. Chickenjoy 1 69 59
TOTAL??
-the总和应该是423的问题是,这将增加一倍的总和
,尤其是圆形是我的代码:
Try
'declaring variable as integer to store the value of the total rows in the datagridview
Dim max As Integer = DataGridView1.Rows.Count - 1
Dim total As String = "Total ----------->"
'getting the values of a specific rows
For Each row As DataGridViewRow In DataGridView1.Rows
'formula for adding the values in the rows
DataGridView1.Rows(max).Cells(4).Value += row.Cells(4).Value
DataGridView1.Rows(max).Cells(3).Value = total
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
设置一个断点并观察代码执行。你会学到很多关于你认为的代码将做什么和它实际上做什么之间的区别,并学习如何使用调试器 – Plutonix