Sample you have an database with field name of Total
For Database get value of total sum for the cell
The "TotalAmount" is my Database Field
- Code:
-
Private Sub btnTotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTotal.Click
Try
Dim totalSum As Integer
For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
totalSum += ds.Tables(0).Rows(i).Item("TotalAmount")
Next
Label1.Text = "Total : " & totalSum.ToString()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Sample
Juan Jan 230, Juan Mar 150, Juan Aug 320
Pedro Jan 120, Pedro Dec 380
For Individual contribute of person to display the total contribute
just type the name to textbox then click the button
- Code:
-
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim Total As Integer = 0
For i As Integer = 0 To DataGridView1.RowCount - 1
If DataGridView1.Rows(i).Cells(1).Value = TextBox1.Text Then
Total += DataGridView1.Rows(i).Cells(2).Value
End If
Next
If Total = 0 Then
MessageBox.Show("No Records Found")
End If
Label1.Text = Total
End Sub