如何在 vb.net 中内部连接两个数据表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22070914/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:55:20  来源:igfitidea点击:

How to inner join two datatables in vb.net

vb.net

提问by lance

Does anyone have an example of how to do an inner join on two datatables in vb.net? I have tried several examples that I found but I haven't gotten one to work thus far.

有没有人有关于如何对 vb.net 中的两个数据表进行内部连接的示例?我已经尝试了几个我发现的例子,但到目前为止我还没有得到一个工作。

回答by Tim Schmelter

Your question is pretty vague, but maybe this helps anyway:

你的问题很模糊,但也许这有帮助:

Dim both = From row1 In dataTable1.AsEnumerable()
           Join row2 In dataTable2.AsEnumerable()
           On row1.Field(Of String)("ColumnName") Equals row2.Field(Of String)("ColumnName")

For Each r1r2 In both
    Dim row1 = String.Format("{0}", String.Join(",", r1r2.row1.ItemArray))
    Dim row2 = String.Format("{0}", String.Join(",", r1r2.row2.ItemArray))
    Console.WriteLine(String.Format("{0} | {1}", row1, row2))
Next