开发者

How can I update with LINQ all records that have equal value?

Can anybody help me with this: I want select all records from datata开发者_运维问答ble which have for example sid=123 and after that save they with sid=456.

How can I do this with LINQ?


items.Where(i=>i.sid == 123).ToList().ForEach(i=>i.sid = 456);

or rather use normal foreach

foreach (var item in items.Where(i=>i.sid == 123))
{
    item.sid = 456
}

edit: sorry, i didn't notice that datatable. you can't query rows on datatable directly (they don't impletement IEnumerable)

but you can do something like this

using System.Data; //System.Data.DataSetExtensions.dll
datatable.AsEnumerable().Where(row=>row.Field<int>("sid") == 1234)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜