开发者

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

开发者 https://www.devze.com 2023-01-12 11:17 出处:网络
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.

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

精彩评论

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

关注公众号