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("物料号") & "|" & dr2("材料名称")
Dim vl As Integer = dr1("下单数量") * dr2("材料用量")
If dic.ContainsKey(nd) = False
dic.Add(nd,vl)
Else
dic(nd) = dic(nd)+ vl
End If
Next
Next
For Each key As String In dic.keys
Dim dr As DataRow = DataTables("材料需求").AddNew() '
Dim ar() As String = key.Split("|")
dr("物料号") = ar(0)
dr("品名") = ar(1)
dr("订单用量") = dic(key)
Next