结合两个数据表 [英] combine two datatables

查看:66
本文介绍了结合两个数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据集ds中有两个数据表.
在表[0]中,我有列mnth,amount,month
看起来像

i have two datatables in dataset ds.
in table[0] i have columns mnth, amount,month
it looks a like

mnth   amount1  month
 9      1500    sep
10     1700    oct
11     2200    nov


在表[1]中,我有列mnth,amount
看起来像


and in table[1] i have columns mnth,amount
it looks a like

mnth   amount2
4       1000 
7       1500
9       800


现在我想合并表并想像这样显示


now i want to merge tables and want to diplay such like this

month amount1  amount2    
4               1000
7               1500
9       1500     800
10      1700
11      2200



这两个表的金额都没有关系..我希望两个表的金额都应按月显示..如果两个表的第9个月都具有金额,则应该只有一行..

我尝试了merge()函数,但没有成功.
请帮助我..



here both table''s amount is irrelevant.. i want that both the amount should display month wise.. if both tables have amount in 9th month then there should be only one row..

i tried merge() function but it didn''t worked.
plz help me out..

推荐答案

查看此线程
^ ]
See this thread
http://stackoverflow.com/questions/285474/merge-2-datatables-and-store-in-a-new-one[^]


尝试
dt.Merge()



谢谢
--RA



Thanks
--RA


DataTable.Merge不是正确的方法,因为merge在行基础上处理数据.如果可能,请使用LINQ代替合并:

http://stackoverflow.com/questions/656013/linq-join-2-datatables-wildcard [^ ]
DataTable.Merge is not the right method, because merge processes data on row base. Instead of merge use LINQ if possible:

http://stackoverflow.com/questions/656013/linq-join-2-datatables-wildcard[^]


这篇关于结合两个数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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