如何合并两个数据表并根据列对新表进行排序? [英] How to merge two data tables and sort the new table according to column?

查看:86
本文介绍了如何合并两个数据表并根据列对新表进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有两个数据表:



第一个DataTable如下所示



< pre lang =c#> AID |标题
-----------------
1 |技术
2 |科学
3 | Asp.net





第二个DataTable如下所示



< pre lang =c#> AID | WID |匹配
------------------------
1 | 1 | 17
1 | 4 | 19
2 | 5 | 22
3 | 6 | 25





合并dataTable DataTable我想要如下,但排序依据匹配



 AID |标题| WID |匹配
------------------------------------------
1 |技术| 1 | 17
1 |技术| 4 | 19
2 |科学| 5 | 22
3 | Asp.net | 6 | 25

解决方案

 选择 AID,标题,WID,匹配来自 table1 
inner join table2 on AID.table1 = AID.table2


为了合并具有不同模式的两个数据表,请参阅发布SO [ ^ ]



至于排序...... 这里的一些建议 [ ^ ]


Assume that I have two datatables:

the first DataTable is like the following

AID | Title 
-----------------
1  | Technology 
2  | Science 
3  | Asp.net 



The second DataTable is like the following

AID | WID | Matching 
------------------------
1   | 1   | 17 
1   | 4   | 19 
2   | 5   | 22 
3   | 6   | 25



the merge dataTable DataTable I want like the following but sorted by Matching

AID  |  Title      |  WID  |  Matching 
------------------------------------------
1    | Technology  |  1    |  17 
1    | Technology  |  4    |  19 
2    | Science     |  5    |  22
3    | Asp.net     |  6    |  25

解决方案

select AID,Title,WID,Matching from table1
inner join table2 on AID.table1=AID.table2


For merging two datatables that have different schema see this post on SO[^]

As for sorting it ... some suggestions here[^]


这篇关于如何合并两个数据表并根据列对新表进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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