想从窗口2的表A副,当前表,选中字段,选中时赋值不重复的数据到表B,执行下面代码,报错找不到DataTables("窗口2_表A"),如何解决?
如果表A和表B的结构不同,或者只需填充部分列,就需要定义数据来源列和数据接收列,例如:
Dim Cols1() As String = {"来源列一","来源列二","来源列三"}
Dim Cols2() As String = {"接收列一","接收列二","接收列三"}
For Each dr1 As DataRow In DataTables("窗口2_表A").Select("[选中] = 1")
Dim dr2 As DataRow = DataTables("表B").AddNew()
For i As Integer = 0 To Cols1.Length -1
dr2(Cols2(i)) = dr1(Cols1(i))
Next
Next
如果要排除重复值,可以用GetValues获得不重复的值,然后再填充:
Dim Vals As List(of String())
Vals = DataTables("窗口2_表A").GetValues("产品|客户")
For i As Integer = 0 To Vals.Count - 1
Dim dr As DataRow = DataTables("表B").AddNew()
dr("产品") = Vals(i)(0)
dr("客户") = Vals(i)(1)
Next