Dim dic As new Dictionary(of String,Integer)
DataTables("材料需求").DataRows.Clear()
For Each dr1 As DataRow In DataTables("生产工单").DataRows
For Each dr2 As DataRow In DataTables("产品BOM明细").Select("[产品名称] = '" & dr1("产品名称") & "'") '
Dim nd As String = dr2("物料号")
Dim nm As String = dr2("材料名称")
Dim vl As Integer = dr1("下单数量") * dr2("材料用量")
If dic.ContainsKey(nm) = False
dic.Add(nm,vl)
Else
dic(nd) = dic(nd)+ vl
dic(nm) = dic(nm)+ vl
End If
Next
Next
For Each key As String In dic.keys
Dim dr As DataRow = DataTables("材料需求").AddNew() '
dr("物料号") = key
dr("品名") = key
dr("订单用量") = dic(key)
Next