如何加入包含excel数据的2个数据表? [英] How can I join 2 datatables containing data from excel?

查看:86
本文介绍了如何加入包含excel数据的2个数据表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天!

如何加入包含从excel导入的数据的2个数据表?

我尝试过使用Merge()但它没有给我想要的结果。



这是我的代码:

Good Day to All!
How can I join 2 datatables which contains data imported from excel?
I've tried using Merge() but it doesn't give my desired result.

Here is my code:

oleTable3 = New DataTable
oleTable3.Merge(oleTable1)
oleTable3.Merge(oleTable2)
dgvCompile.DataSource = oleTable3





< img src =http://i.imgur.com/ImeZLgf.jpgtitle = 来源:imgur.com/>



正如您所看到的,我使用Merge()来获得此结果,但它只会合并2个表中的批名称列。



我想要的结果是这样的:

<img src =http://i.imgur.com/NaAKGea.jpgtitle =source:imgur.com/>



具有相同批次名称的数据将在一行中。



任何帮助将是ap preiated!



<img src="http://i.imgur.com/ImeZLgf.jpg" title="source: imgur.com" />

As you can see, I use Merge() to get this result, but it only merge the "Batch Name" column from the 2 tables.

My desired result is something like this:
<img src="http://i.imgur.com/NaAKGea.jpg" title="source: imgur.com" />

The data that have same "Batch Name" will be in 1 row.

Any help will be appreciated!

推荐答案

一种简单的方法是使用LINQ加入数据。看看这里的例子:

查询表达式语法示例:连接运算符(LINQ to DataSet) [ ^ ]
One easy way is to use LINQ to join the data. Have a look at the examples over here:
Query Expression Syntax Examples: Join Operators (LINQ to DataSet)[^]


这篇关于如何加入包含excel数据的2个数据表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆