如何将记录数从一个数据表复制到另一个数据表 [英] How Can I Copy No. Of Records From One Datatable To Other

查看:126
本文介绍了如何将记录数从一个数据表复制到另一个数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我在一个表中有10000条记录,我只想从此Datable A到Datatable B记录100条记录,除了循环以外,还有什么简单的方法吗?

say i have 10000 records in one table i just want 100 record from this datable A to Datatable B , is there any easy way other than loop ?

推荐答案

尝试lambda表达式:
Try lambda expression:
Datatable1.AsEnumerable().Where(s=>s.Field<stirng>("SomeColumn") == "SomeValue").CopyToDataTable(Datatable2, LoadOption.Upsert);
//Here Datatable1 is having 1000 records(assume), and you are copying the datatable to Datatable2
</stirng>




[更新]
那呢?




[Update]
Then how about this?

DataRow[] dr = DataTable1.Select("ColumnName='columnvalue'");


然后:


and then:

foreach (DataRow row in dr ) {
   DataTable2.ImportRow(row);
}


-Amy


你好,
如果您使用的是LINQ,则使用另一种解决方案...
Hello ,
If you are using LINQ ,then another solution ...
<br />
table1.AsEnumerable().Take(noofcount).CopyToDataTable(table2,LoadOption.OverwriteChanges);<br />



谢谢



thanks


这篇关于如何将记录数从一个数据表复制到另一个数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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