从第一个填充第二个数据表 [英] populate second datatable from the first

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

问题描述


如何从第一个datatable1(dt1)填充datatable2(dt2),但我不希望dt2依赖于dt1.
例如:
我正在从dt1填充dt2.但是,如果dt1中的数据发生变化,则dt2也会发生变化.
我不想更改dt2.
请问如何在dt2上执行此操作?
谢谢


Hi,
How can I populate datatable2 (dt2) from the first datatable1 (dt1), but I do not want dt2 to be dependant of dt1.
For example:
I am populating dt2 from dt1. But if the data in dt1 changes, so does dt2.
I do not want dt2 to change.
How can I do this for dt2 please?
Thanks

i.e.

datatable dt1 = ds.table[0]...
...

//copy the distinct field to dt2
DataTable dt2 = dt.DefaultView.ToTable(true, "FieldName");

我必须对dt2的Binding上下文做任何事情吗?

感谢

do I have to do anything with Binding context for dt2 ?

Thanks

推荐答案

只需使用DataTable的克隆 ^ ],然后重新填充表.
Just use DataTable''s Clone property[^] and then repopulate the table.


实际上,使用DataTable(或至少是DataRows)的方式是相同,相同的对象.如果确实要处理副本,则该副本不会表现为同步",请使用方法DataTable.Clone();.请参阅此处: http://msdn.microsoft.com/en-us/library /system.data.datatable.clone.aspx [
The way you are using it the DataTable (or at least the DataRows) is(are) in reality the same, identical object(s). If you do want a copy to work on that will not behave "synchronized" use the method DataTable.Clone();. See here: http://msdn.microsoft.com/en-us/library/system.data.datatable.clone.aspx[^].

DataTable dt1 = ds.table[0];
DataTable dt2 = dt1.Clone();
// Populating the cloned DataTable is left as an excercise to OP :)



问候,

曼弗雷德(Manfred)



Regards,

Manfred


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

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