[英]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
和cat行的類別。 問題是我不知道如何從數據表中的總和中獲取價值。
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將顯示總和。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.