创建ADO.NET数据视图只显示选定列只显示、视图、数据、ADO

2023-09-03 05:11:35 作者:你猜我是谁

在C#和放大器; .NET,可以创建一个数据视图仅包括一个的正确的子集的的DataColumn 第一个给定的数据表

In C# & .NET, can one create a DataView that includes only a proper subset of the DataColumns of a given DataTable?

在关系代数方面,一是分配的RowFilter 以进行选择操作(西格玛)。将如何执行投影操作(PI)?

In terms of relational algebra, one assigns a RowFilter in order to perform a "selection" operation (σ). How would one perform a "projection" operation (π)?

推荐答案

您不能这样做,但你可以创建表的只有列你想有一个副本:

You can't do that, but you can create a copy of the table with only the columns you want :

DataView view = new DataView(table);
DataTable table2 = view.ToTable("FirstColumn", "SecondColumn", "ThirdColumn");

您也可以选择返回具有不同值的选定列行:

Optionally you can return rows that have distinct values for the selected columns :

DataView view = new DataView(table);
DataTable table2 = view.ToTable(true, "FirstColumn", "SecondColumn", "ThirdColumn");