创建仅显示选定列的 ADO.NET DataView [英] Create ADO.NET DataView showing only selected Columns

查看:22
本文介绍了创建仅显示选定列的 ADO.NET DataView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 C# 中 &.NET,可以创建一个 DataView 只包含给定 DataTableDataColumn正确 子集?

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

在关系代数方面,分配一个 RowFilter 以执行选择"操作 (σ).如何执行投影"操作 (π)?

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(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");

这篇关于创建仅显示选定列的 ADO.NET DataView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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