我很难加入 2 个数据表,结果是加入了数据表。
第一个数据表(标签)保存包括打印机标识的数据。第二个数据表(打印机)保存打印机引用(id > unc)
我想拥有一个数据表作为最终结果(加入),其中包含来自第一个数据表的所有数据以及第二个数据表的字段(unc)。
这就是我一直在尝试的:(注意固定路径是为了方便......)
Sub Main()
Dim ds1 As new DataSet
ds1.ReadXml("C:\Program Files (x86)\[COMPANY]\ASW2XML\BICOLOR_a07bfc62-501e-4444-9b6e-3b9d3550e1a4.xml")
Dim ds2 As New DataSet
Dim li As string()
li = IO.File.ReadAllLines("C:\Program Files (x86)\[COMPANY]\ASW2XML\printers.dat")
Dim printers As New DataTable("Printers")
printers.Columns.Add("REPRT2")
printers.Columns.Add("REPRT3")
For Each s In li.ToList
Dim dr As DataRow = printers.NewRow
dr.Item(0) = s.Split("=")(0)
dr.Item(1) = s.Split("=")(1)
printers.Rows.Add(dr)
Next
printers.AcceptChanges
Dim labels As DataTable = ds1.Tables(0)
Dim joined As new DataTable("data")
'Dim lnq = From label In labels.AsEnumerable Join printer In printers.AsEnumerable On label("REPRT") Equals printer("REPRT2") Select printer
'Dim lnq = From l In labels Group Join p In printers On l Equals p("REPRT2") Into Group From p In Group Select label = l, ppath = If(p Is Nothing, "(Nothing)", p("REPRT3"))
Dim lnq = labels.AsEnumerable().Where(Function(o)printers.Select("REPRT2 =" & o.Item("REPRT").ToString).Length = 0)
joined = lnq.CopyToDataTable
End Sub
感谢您的帮助和启发!
grtz -S-