0

I have a data table having the two columns Select and Value.

Select Value
 0      213
 0      314
 0      282

I have an integer array called Ids={213,314} If the values of Ids occur in the data table column "values" then update the "select" column as 1. I have to do this using Linq. Please help

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
Intruder
  • 147
  • 1
  • 12

1 Answers1

0

Linq is for querying, not for updating. So you have to do task in two steps. First is querying for rows which should be updated:

var rows = from r in table.AsEnumerable()
           where Ids.Contains(r.Field<int>("Value"))
           select r;
// Or lambda syntax
// rows = table.AsEnumerable().Where(r => Ids.Contains(r.Field<int>("Value")))

Second part is updating selected rows, which does not involve Linq:

foreach(var row in rows)
    row.SetField("Select", 1);
Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459