开发者

Iterating DataView for Update

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 exe开发者_如何转开发cute the following?

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


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜