如何进行数据表合并? [英] How to do Datatable Merging ?

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

问题描述

i have two datatables,

DataTable dt1=obj.SomeFunction();
DataTable dt2=obj.SomeFunction();

// I put an iteration on dt1 to select some value from dt2 e.x

foreach(DataRow row in dt1.Rows)

{
string s=dt1.row["ColumnName"].ToString();

var newquery = from b in dt2.AsEnumerable()
               let somevariable= b.Field<string>("DataColumn").ToString()
                      where (s== somevariable)

                      select new
                      {
                          somevariable

                      };
//here i want to add each itteration into list<> and then. add the list<> to dt1
}

推荐答案

Try
Try
dt1.Merge(dt2.AsEnumerable().Where(x=>x.Field<string>("DataColumn") == somevariable).CopyToDataTable());


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

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