views:

27

answers:

1

I have a DataView which filters

inputView.RowFilter = "isnull(" + ID1 + ",'')<>'' and isnull(" + reason + ",0)=0";

after this filter i have to update "IsVerified" column of inputView to "1"

Is there something in LINQ to execute the following?

inputView.RowFilter.ForEach(x=>x.Field<IsVerified> =1);
+1  A: 

If you want to use LINQ on your DataView, you'll have to create your own extension method on the DataView. The DataView does not natively have a .ToList() method, which is where the .ForEach() is defined.

Create your Extension Method for the DataView.

public static class DataViewExtensions
{
    public static List<DataRowView> ToList(this DataView v)
    {
        List<DataRowView> foo = new List<DataRowView>();

        for (int i = 0; i < v.Count; i++)
        {
            foo.Add(v[i]);
        }
        return foo;
    }

}

Your DataView can now be called this like:

inputView.ToList().ForEach(x=>x["IsVerified"]=1);

Some developers may prefer the full .NET foreach (var x in y) statement, but this will do the same.

A full console application proo-of-concept: http://pastebin.com/y9z5n6VH

p.campbell