coder
coder

Reputation: 2000

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

Upvotes: 1

Views: 1056

Answers (1)

cuongle
cuongle

Reputation: 75306

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

Upvotes: 1

Related Questions