I cannot query a DataView
without casting. The two lines of code in the method IsPresent are taken from "LINQ - Specified cast is not valid with dataview use" and seem to work for everyone, except for one commenter. I am "using" the LINQ namespace, so what is my problem?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// works
DataView o = new DataView();
var p = from x in o.Cast<DataRowView>() where x.Row.Field<bool>("xxx") select x.Row;
}
public static bool IsPresent(DataView dvDataTag, string colName)
{
// does not work
int count = dvDataTag.Count(drv => string.Equals("1", drv[colName].ToString()));
return dvDataTag.Any(drv => string.Equals("1", drv[colName].ToString()));
}
}
}
Error 2 'System.Data.DataView' does not contain a definition for 'Any' and no extension method 'Any' accepting a first argument of type 'System.Data.DataView' could be found (are you missing a using directive or an assembly reference?) A:\TEMP\ConsoleApplication1\ConsoleApplication1\Program.cs ConsoleApplication1 20 20