Arrays 在visual basic中循环数据集并将数据存储在数组中

Arrays 在visual basic中循环数据集并将数据存储在数组中,arrays,vb.net,loops,dataset,Arrays,Vb.net,Loops,Dataset,我试图将所有组加载到一个数组中,然后在这些组中循环,查看每个代理拥有多少资产,如果资产多于代理,则将它们移动到我们的虚拟组0。但我不熟悉这个数据集和TableAdapator 基本上 组--代理--资产 所以组2有2个额外的资产我想将它们移动到空组0 请引导 Dim rs, lines rs = cn.Execute("select grp from tskmsgrp where listid = 0;") Dim da As New System.Data.OleDb.OleDbDataAd

我试图将所有组加载到一个
数组中
,然后在这些组中循环,查看每个代理拥有多少资产,如果资产多于代理,则将它们移动到我们的虚拟组0。但我不熟悉这个
数据集
TableAdapator

基本上 组--代理--资产

所以组2有2个额外的资产我想将它们移动到空组0

请引导

Dim rs, lines
rs = cn.Execute("select grp from tskmsgrp where listid = 0;")

Dim da As New System.Data.OleDb.OleDbDataAdapter()
Dim da_line As New System.Data.OleDb.OleDbDataAdapter()
Dim ds As New DataSet()
da.Fill(ds, rs, "grp")

MsgBox("There are  total products." & ds.Tables(0).Rows.Count.ToString)
For Each a As DataRow In ds.Tables(0).Rows
    lines = cn.Execute("select count(*) from tsklines where grp ='" & a(0) & "';")
    Dim ds_lines As New DataSet()
    da_line.Fill(ds_lines, lines, "lines")
    MsgBox("Lines for group." & a(0) & " -- " & ds_lines.Tables(0).Rows.Count.ToString)
Next
有两点--你可以计算出细节

  • 循环中不需要select语句,因为您可以 访问a行中的数据
  • 您不需要再次填充数据集,只需更新ds即可。你可以 循环完成后立即更新所有内容
  • Dim rs, lines
    rs = cn.Execute("select grp from tskmsgrp where listid = 0;")
    
    Dim da As New System.Data.OleDb.OleDbDataAdapter()
    Dim da_line As New System.Data.OleDb.OleDbDataAdapter()
    Dim ds As New DataSet()
    da.Fill(ds, rs, "grp")
    
    MsgBox("There are  total products." & ds.Tables(0).Rows.Count.ToString)
    For Each a As DataRow In ds.Tables(0).Rows
        lines = cn.Execute("select count(*) from tsklines where grp ='" & a(0) & "';")
        Dim ds_lines As New DataSet()
        da_line.Fill(ds_lines, lines, "lines")
        MsgBox("Lines for group." & a(0) & " -- " & ds_lines.Tables(0).Rows.Count.ToString)
    Next