How do I display only certain columns from a data table?(如何仅显示数据表中的某些列?)
问题描述
我正在使用返回数据集的 Web 服务.在这个数据集中有 5 个表,比如说表 A、B、C、D、E.我使用表 A.
I'm using a web service that returns a dataset. in this dataset there are 5 table, let's say table A, B, C, D, E. I use table A.
所以
DataTable dt = new DataTable()
dt = dataset.Table["A"]
现在在这个数据表中有列 a1,a2,a3,a4,a5,a6,a7.
Now in this datatable there are columns a1,a2,a3,a4,a5,a6,a7.
假设我只想获取列 a3 和 a4,然后将其绑定到我的数据网格.
Let's say I only want to get columns a3 and a4 then bind it to my datagrid.
我该怎么做?
推荐答案
忽略您拥有的数据比您需要的多的事实.将 AutoGenerateColumns 设置为 false.为 a3 和 a4 创建 BoundColumns.
Ignore the fact that you have more data than you need. Set AutoGenerateColumns to false. Create BoundColumns for a3 and a4.
这篇关于如何仅显示数据表中的某些列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何仅显示数据表中的某些列?
基础教程推荐
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
