【问题标题】:How to filter two DataTables in C#?如何在 C# 中过滤两个数据表?
【发布时间】:2013-04-09 06:38:28
【问题描述】:

如何在 C# 中过滤两个表?表一包含全部数据,表二包含表一的部分内容?

【问题讨论】:

标签: c# filter datatable


【解决方案1】:

您到底想做什么(从您的问题中不清楚)?取table1,过滤,然后把结果传给table2? 那么:

DataView dv = table1.AsDataView();
dv.RowFilter = fexpression; // for example "MyID = 3"
DataTable table2 = dv.ToTable();

// If you want typed datatable, you can do it like this (although there are other ways):
MyTypedDataTable table2 = new MyTypedDataTable();
DataTable tempTable = dv.ToTable();
table2.Merge(tempTable);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-14
    • 2017-04-25
    • 2013-02-03
    • 2019-09-06
    • 1970-01-01
    • 2010-09-29
    • 2015-02-28
    • 2015-11-20
    相关资源
    最近更新 更多