过滤所有列值的特定行数据

时间:2022-02-11 01:30:18

I have a datatable in my application which has only one row which is as below.

我的应用程序中有一个数据表,只有一行,如下所示。

pcode d1 d2 d3 d4 d5 d6

10001 0  1   1  0  1  1

Now i want to filter the datatable to get only the columns which has the value 1 except the pcode column(i.e i want only the columns d2,d3,d5,d6).The above datatable comes from database.Is there any way to filter the datatable or if i can do it with database table how can i do so?Any sugessions?

现在我想过滤数据表,只得到除了pcode列之外的值为1的列(即我只想要列d2,d3,d5,d6)。上面的数据表来自数据库。有什么方法可以过滤数据表,或者如果我可以用数据库表做,我怎么能这样做?任何sugessions?

1 个解决方案

#1


1  

Sound like:

听起来像:

List<string> result = dt.Columns.Cast<DataColumn>()
            .Where(c => c.ColumnName != "pcode")
            .Where(c => dt.Rows[0][c].ToString() == "1")
            .Select(c => c.ColumnName)
            .ToList();

#1


1  

Sound like:

听起来像:

List<string> result = dt.Columns.Cast<DataColumn>()
            .Where(c => c.ColumnName != "pcode")
            .Where(c => dt.Rows[0][c].ToString() == "1")
            .Select(c => c.ColumnName)
            .ToList();