繁体   English   中英

我如何总计数据表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和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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM