如何仅显示数据表中的某些列?数据表

2023-09-06 05:11:33 作者:等不到的路人

我正在使用返回数据集的 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.为 a3a4 创建 BoundColumns.

Ignore the fact that you have more data than you need. Set AutoGenerateColumns to false. Create BoundColumns for a3 and a4.