我如何从数据 table vb.net 中计算列和行的总和
how do i total the sum column and row from data table vb.net
Category projectName[1] projectName[2] ... total<br/>
cat[1] 0 1 ??<br/>
cat[2] 2 3 ??<br/>
.. .... ..... .....<br/>
total ?? ?? ??<br/>
这是我的代码,用于显示我的 projectName
类别和猫行。问题是我不知道如何获取数据总和的价值 table。
ExportDT.Columns.Add("Category")
For Each ProjectRow As Data.DataRow In TempProjectDT.Rows
ExportDT.Columns.Add(ProjectRow.Item("NameOfProject").ToString.Trim)
Next
Dim NewRow As Data.DataRow
Dim ComplaintDV As New Data.DataView(TempComplaintDT)
For Each CategoryRow As Data.DataRow In TempComplaintCatDT.Rows
NewRow = ExportDT.NewRow
NewRow.Item("Category") = CategoryRow.Item("Category").ToString
For nLoop As Integer = 1 To ExportDT.Columns.Count - 1
ComplaintDV.RowFilter = "ComplaintCategory='" & CategoryRow.Item("Category").ToString & "' AND NameOfProject='" & ExportDT.Columns(nLoop).ColumnName & "'"
If ComplaintDV.Count > 0 Then
NewRow.Item(ExportDT.Columns(nLoop).ColumnName) = ComplaintDV.Count
Else
NewRow.Item(ExportDT.Columns(nLoop).ColumnName) = "0"
End If
Next
ExportDT.Rows.Add(NewRow)
Next
让我们对此做一个假设:
For i As Integer = 0 To 2
yourTable.Rows(i).Cells(2).Value = yourTable.Rows(i).Cells(0).Value + yourTable.Rows(i).Cells(1).Value
Next
它可以让您计算 Column3 的列。 Column3 将显示总和。
Category projectName[1] projectName[2] ... total<br/>
cat[1] 0 1 ??<br/>
cat[2] 2 3 ??<br/>
.. .... ..... .....<br/>
total ?? ?? ??<br/>
这是我的代码,用于显示我的 projectName
类别和猫行。问题是我不知道如何获取数据总和的价值 table。
ExportDT.Columns.Add("Category")
For Each ProjectRow As Data.DataRow In TempProjectDT.Rows
ExportDT.Columns.Add(ProjectRow.Item("NameOfProject").ToString.Trim)
Next
Dim NewRow As Data.DataRow
Dim ComplaintDV As New Data.DataView(TempComplaintDT)
For Each CategoryRow As Data.DataRow In TempComplaintCatDT.Rows
NewRow = ExportDT.NewRow
NewRow.Item("Category") = CategoryRow.Item("Category").ToString
For nLoop As Integer = 1 To ExportDT.Columns.Count - 1
ComplaintDV.RowFilter = "ComplaintCategory='" & CategoryRow.Item("Category").ToString & "' AND NameOfProject='" & ExportDT.Columns(nLoop).ColumnName & "'"
If ComplaintDV.Count > 0 Then
NewRow.Item(ExportDT.Columns(nLoop).ColumnName) = ComplaintDV.Count
Else
NewRow.Item(ExportDT.Columns(nLoop).ColumnName) = "0"
End If
Next
ExportDT.Rows.Add(NewRow)
Next
让我们对此做一个假设:
For i As Integer = 0 To 2
yourTable.Rows(i).Cells(2).Value = yourTable.Rows(i).Cells(0).Value + yourTable.Rows(i).Cells(1).Value
Next
它可以让您计算 Column3 的列。 Column3 将显示总和。