0

我有一个六行多列的数据表。列命名为 Operation1、folder1、quantity1、OPeration2、folder2、quantity2 等... 代码如下:

    Dim dt As New DataTable

    'adding columns to the datatble
    For i = 1 To 60
        dt.Columns.Add("Operation" & i)
        dt.Columns.Add("folder" & i)
        dt.Columns.Add("quantity" & i)
    Next

    'adding datarows
    Dim dr1 As DataRow = dt.NewRow
    Dim dr2 As DataRow = dt.NewRow
    Dim dr3 As DataRow = dt.NewRow
    Dim dr4 As DataRow = dt.NewRow
    Dim dr5 As DataRow = dt.NewRow
    Dim dr6 As DataRow = dt.NewRow

    For i = 1 To 10
        dr1("Operation" & i) = GroupBox1.Controls("l1ob" & i)
        dr1("Folder" & i) = GroupBox1.Controls("l1f" & i)
        dr1("Quantity" & i) = GroupBox1.Controls("l1Qty" & i)
        dr2("Operation" & i) = GroupBox2.Controls("l2ob" & i)
        dr2("Folder" & i) = GroupBox2.Controls("l2f" & i)
        dr2("Quantity" & i) = GroupBox2.Controls("l2Qty" & i)
        dr3("Operation" & i) = GroupBox3.Controls("l3ob" & i)
        dr3("Folder" & i) = GroupBox3.Controls("l3f" & i)
        dr3("Quantity" & i) = GroupBox3.Controls("l3Qty" & i)
        dr4("Operation" & i) = GroupBox4.Controls("l5ob" & i)
        dr4("Folder" & i) = GroupBox4.Controls("l5f" & i)
        dr4("Quantity" & i) = GroupBox4.Controls("l5Qty" & i)
        dr5("Operation" & i) = GroupBox5.Controls("l6ob" & i)
        dr5("Folder" & i) = GroupBox5.Controls("l6f" & i)
        dr5("Quantity" & i) = GroupBox5.Controls("l6Qty" & i)
        dr6("Operation" & i) = GroupBox6.Controls("l4ob" & i)
        dr6("Folder" & i) = GroupBox6.Controls("l4f" & i)
        dr6("Quantity" & i) = GroupBox6.Controls("l4Qty" & i)
    Next

    'adding the rows to the datatble
    dt.Rows.Add(dr1)
    dt.Rows.Add(dr2)
    dt.Rows.Add(dr3)
    dt.Rows.Add(dr4)
    dt.Rows.Add(dr5)
    dt.Rows.Add(dr6)

我现在需要做的是在六行中的任何一行中找到重复的文件夹列,并总结相应的数量列并存储文件夹名称和总量以供以后检索......有没有办法实现这一点?请帮忙...

4

1 回答 1

1

这是从 DataColumn 中检索列名的方法:

dt.Columns(1).ColumnName 

要获取 DataTable 中所有 DataColumns 的名称:

Dim name(dt.Columns.Count) As String
Dim i As Integer = 0
For Each column As DataColumn In DT.Columns
  name(i) = column.ColumnName
  i += 1
Next

您可以对名称数组执行搜索以查找匹配的列名并添加数量。

于 2013-04-22T04:14:44.453 回答