需要合并两个或多个数据表 vb.net

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26148592/
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 18:18:16  来源:igfitidea点击:

Need to merge two or more datatable vb.net

vb.netdatatable

提问by Shai

I have 5 different DataTables. Each DataTable has always the same amount of rows with one repeated column called EmployeeID, which is primary key. Now I need to combine all columns from all tables along with data into one DataTable All DataTable are part of the same DataSet called Employee

我有 5 个不同的数据表。每个 DataTable 始终具有相同数量的行和一个称为 EmployeeID 的重复列,它是主键。现在我需要将所有表中的所有列与数据合并到一个数据表中 所有数据表都是名为 Employee 的同一个数据集的一部分

DT1
EmployeeID, Name   , Age , Phone
1,          Mr. A  , 45  , 123456789

DT2
EmployeeID, Address      , Rank        , Title
1,          Main Street  , Top Level   , Manager

Expected output. 
The DTAll table will have the following columns with data
EmployeeID, Name   , Age,  phone     , Address     , Rank      , Title
1           Mr. A  , 45 ,  123456789 , Main Street , Top Level , Manager

回答by John Bustos

If I'm understanding your question correctly, I would suggest you look into the DataTable.Marge()method - like here.

如果我正确理解您的问题,我建议您研究该DataTable.Marge()方法 - 就像这里

It would look like something along the following code:

它看起来像下面的代码:

    DT1.PrimaryKey = New DataColumn() {DT1.Columns("EmployeeID")}
    DT2.PrimaryKey = New DataColumn() {DT2.Columns("EmployeeID")}

    DT1.Merge(DT2)

Hope I understood correctly and that that helped!

希望我理解正确,这有帮助!