加入msgbox测试是否弹出,你要学会自己调试代码啊。
Dim dic As new Dictionary(of String,Integer)
DataTables("BOM分析表_需求明细").DataRows.Clear()
For Each dr1 As DataRow In DataTables("生产在制品").DataRows
msgbox(1)
For Each dr2 As DataRow In DataTables("BOM基础数据").Select("[成品编码] = '" & dr1("成品编码") & "'")
msgbox(2)
Dim nm As String = dr1("生产批次") & "|" & dr2("材料编码")
Dim vl As Integer = dr1("计划数量") * dr2("单车用量")
If dic.ContainsKey(nm) = False
dic.Add(nm,vl)
Else
dic(nm) = dic(nm)+ vl
End If
Next
Next
msgbox(dic.Count)
For Each key As String In dic.keys
msgbox("a")
Dim dr As DataRow = DataTables("BOM分析表_需求明细").AddNew()
Dim cr As Row = Tables("生产在制品").Current
dr("材料编码") = key.split("|")(1)
dr("需求数量") = dic(key)
dr("生产批次") = key.split("|")(0)
dr("毛坯产地") = cr("毛坯产地")
dr("下达日期") = cr("下达日期")
Next