创建仅显示选定列的 ADO.NET DataView

发布于 2024-07-30 01:26:14 字数 182 浏览 10 评论 0原文

在 C# 和 .NET,可以创建一个仅包含给定 DataTable 的 DataColumn适当子集的 DataView

就关系代数而言,分配一个RowFilter以执行“选择”操作(σ)。 如何执行“投影”运算(π)?

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦里兽 2024-08-06 01:26:14

好吧,我看不出“想要”这样做的任何理由...记住,DataView 只是指向原始表中行的指针列表,显然没有办法从原始表中删除列...至少不会影响使用该表的所有其他功能...只需使用您想要的列...

Well I can't see any reason for "wanting" to do that... Remember, a DataView is just a list of pointers to the rows in the original table, and there is obviously no way to remove columns from the the original table... at least not without affecting every other function utilizing that table... Just only use the columns you want...

笛声青案梦长安 2024-08-06 01:26:14

您不能这样做,但您可以创建仅包含所需列的表副本:

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

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

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

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(false, "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");
℉服软 2024-08-06 01:26:14

创建 dataview 作为从一个表到另一表的交换,并使用 dtswap 作为数据源。

DataView dw = new DataView(dtfee);
            DataTable dtswap = new DataTable();
            dtswap = dw.ToTable(true,"Fees", "FeeAmount", "Year", "CollectorName", "Month");

create dataview as a swap from one table to other table, and use the dtswap as datasource.

DataView dw = new DataView(dtfee);
            DataTable dtswap = new DataTable();
            dtswap = dw.ToTable(true,"Fees", "FeeAmount", "Year", "CollectorName", "Month");
傾旎 2024-08-06 01:26:14

DataSet 及其关联类型无法执行关系操作。

DataSet and its associated types have no ability to perform relational operations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文