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.
这篇关于如何仅显示数据表中的某些列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何仅显示数据表中的某些列?
基础教程推荐
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 将数据集转换为列表 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 如果条件可以为空 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
