문제

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

도움이 되었습니까?

해결책

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top