tags:

views:

35

answers:

1

Hi all.

Can anybody help me with this: I want select all records from datatable which have for example sid=123 and after that save they with sid=456.

How can I do this with LINQ?

+4  A: 
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)
Kikaimaru
I'd like to select records from datatable.
misho