简体   繁体   中英

Filter particular row of Datatable for all column values

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(ie 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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM